Hi all,
I encounter a problem when i’m stubing out a library file.
The rails version is 2.3.4.
[How to reproduce]
- Create a file payment_gateway.rb in subdirectory lib/.
[code]
class PaymentGateway
def self.collect
p ‘lib/payment_gateway’
true
end
end
- Create a file payment_gateway.rb in subdirectory test/mocks/test.
[code]
require ‘lib/util/payment_gateway’
class PaymentGateway
def self.collect
p ‘mock/payment_gateway’
false
end
end
- Create a method in any unit test file to test this method.
The actual result is invoking the method in the mock file, and the
output is
‘mock/payment_gateway’
false
But if i add the following code in the application_controller.rb
[code]
require ‘util/payment_gateway’
The actual result is invoking the method in the lib file, and the output
is
‘lib/payment_gateway’
true
I don’t know why is that, could anyone give me some help?
Thanks very much.