Let's assume that 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 stub whole bar method using:
Foo.any_instance.expects(:bar).at_least_once.returns(false)
However if I only want to stub when param1 of bar method is true, I couldn't find a way to do:
I also looked at with, and has_entry, and it seems it only applies to a single 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
................................................... EDITED THE FOLLOWING .............................................
Thanks, nash
Not familiar with rspec, so I tried with unit test with any_instance, and it seems 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