Suppose I have this class
class Foo def bar(param1=nil, param2=nil, param3=nil) :bar1 if param1 :bar2 if param2 :bar3 if param3 end end
I can drown out the whole bar method using:
Foo.any_instance.expects(:bar).at_least_once.returns(false)
However, if I only want to stub when param1 of the bar method is correct, I could not find a way to do:
I also looked with and has_entry, and it seems that this only applies to one parameter.
I was expecting some function like this.
Foo.any_instance.expects(:bar).with('true',:any,:any).returns(:baz1) Foo.any_instance.expects(:bar).with(any,'some',:any).returns(:baz2)
thanks
.................................................. CHANGED THE FOLLOWING .............................................
Thanks nash
Not familiar with rspec, so I tried using unit test with any_instance and it seems to work
require 'test/unit' require 'mocha' class FooTest < Test::Unit::TestCase def test_bar_stub foo = Foo.new p foo.bar(1) Foo.any_instance.stubs(:bar).with { |*args| args[0]=='hee' }.returns('hee') Foo.any_instance.stubs(:bar).with { |*args| args[1]=='haa' }.returns('haa') Foo.any_instance.stubs(:bar).with { |*args| args[2]!=nil }.returns('heehaa') foo = Foo.new p foo.bar('hee') p foo.bar('sth', 'haa') p foo.bar('sth', 'haa', 'sth') end end