Steve Eichert
2007-Jun-21 03:55 UTC
[mocha-developer] only checking certain parameters for a method
I''m writing a test where I only care about one of the parameters being sent to the method, does anyone think having a way to say that any value for a parameter which I don''t care about is valid? I''m thinking something like: def test_charge_is_for_10_bucks gateway = test_gateway 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) member.expects(:purchase).with(1000, :any).returns(TestResponse.new) member.charge end On a slightly unrelated note, I was trying to find a way to search the mailing list archives here: http://rubyforge.org/pipermail/mocha-developer/but wasn''t able to figure anything out. Does anyone have any suggestions? Cheers, Steve
James Mead
2007-Jun-21 08:49 UTC
[mocha-developer] only checking certain parameters for a method
You should be able to use the anything parameter matcher to do what you want (http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000009). i.e. member.expects(:purchase).with(1000, anything).returns(TestResponse.new ) -- James. http://blog.floehopper.org
James Mead
2007-Jun-21 08:54 UTC
[mocha-developer] only checking certain parameters for a method
On 21/06/07, Steve Eichert <steve.eichert at gmail.com> wrote:> > On a slightly unrelated note, I was trying to find a way to search the > mailing list archives here: > http://rubyforge.org/pipermail/mocha-developer/but wasn''t able to > figure anything out. Does anyone have any suggestions? >How about googling for "site:rubyforge.org/pipermail/mocha-developer/{search}" replacing {search} with your search keywords. -- James. http://blog.floehopper.org
Steve Eichert
2007-Jun-21 12:05 UTC
[mocha-developer] only checking certain parameters for a method
Perfect, thanks! I realized after I sent the question about trying to search that I could just use google with site: to do what I wanted. Sorry for being lame :) On 6/21/07, James Mead <jamesmead44 at gmail.com> wrote:> > You should be able to use the anything parameter matcher to do what you > want > (http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000009). > > i.e. member.expects(:purchase).with(1000, anything).returns( > TestResponse.new > ) > -- > James. > http://blog.floehopper.org > _______________________________________________ > mocha-developer mailing list > mocha-developer at rubyforge.org > http://rubyforge.org/mailman/listinfo/mocha-developer >