method
should_receive
1.2.8 -
Show latest stable
- Class:
Spec::Mocks::Methods
should_receive(sym, opts={}, &block)public
No documentation available.
# File lib/spec/mocks/methods.rb, line 4
def should_receive(sym, opts={}, &block)
__mock_proxy.add_message_expectation(opts[:expected_from] || caller(1)[0], sym.to_sym, opts, &block)
end 1Note
Usage examples
Basic usage:
User.should_receive(:find).with(:all, anything).and_return("hello world")
Now:
User.find(:all, :conditions => "foo") #=> "hello world"
But you can also use blocks for more complex matching logic. For example:
User.should_receive(:find) { |*args|
if args.size == 2
"received two arguments"
else
"something else"
end
}.at_least(:once)
Now:
User.find(:all, :conditions => "bar") #=> "received two arguments"
User.find(5) #=> "something else"
Of course normally you'd return mocks instead of strings.