Steve Eichert
2007-Jun-21 03:39 UTC
[mocha-developer] expects with returns that returns the return value of the actual method
I''m trying to test some code that''s using active_merchant using the following test. What I''d like to be able to do is verify that purchase is called, however, rather than specifying the return value for purchase with returns, I''d like it to return the actual return value provided if you called the non mocked purchase method. Is this possible? def test_charge gateway = ActiveMerchant::Billing::Base.gateway(:bogus).new ActiveMerchant::Billing::Base.mode = :test member = Member.new member.credit_card_number = "1" member.expiration_date = "9/19/2007" member.payment_method = "bogus" member.first_name = "Steve" member.last_name = "Eichert" member.expects(:active_merchant_gateway).returns(gateway) # gateway.expects(:purchase).returns(:non_mocked_return) member.charge assert member.paid end
James Mead
2007-Jun-21 09:00 UTC
[mocha-developer] expects with returns that returns the return value of the actual method
While it would be technically possible, Mocha doesn''t support this. I doubt it ever will because what you describe is not really what mocking is all about. Why do you want to get the real result? Can you not record a sample result and then use this as a canned result in the test? -- James. http://blog.floehopper.org
Steve Eichert
2007-Jun-21 12:09 UTC
[mocha-developer] expects with returns that returns the return value of the actual method
In my specific example I want to use the real result because the real result being used is already a "fake" object that is returning canned results depending on the inputs. I''m trying to test some logic that''s making use of active_merchant, and am using their "bogus" gateway that returns success/failures depending on predefined input. I can definitely go the route you mentioned and record a sample result, I was just hoping I could re-use the already implemented logic. I actually think that breaking my tests apart to test more specific things per test will help as well. Thanks, Steve On 6/21/07, James Mead <jamesmead44 at gmail.com> wrote:> > While it would be technically possible, Mocha doesn''t support this. I > doubt > it ever will because what you describe is not really what mocking is all > about. > > Why do you want to get the real result? Can you not record a sample result > and then use this as a canned result in the test? > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >