Class | FlexMock::Expectation |
In: |
lib/flexmock/expectation.rb
|
Parent: | Object |
An Expectation is returned from each should_receive message sent to mock object. Each expectation records how a message matching the message name (argument to should_receive) and the argument list (given by with) should behave. Mock expectations can be recorded by chaining the declaration methods defined in this class.
For example:
mock.should_receive(:meth).with(args).and_returns(result)
expected_args | [R] | |
mock | [RW] | |
order_number | [R] |
Declares that the method will raise the given exception (with an optional message) when executed.
Declare that the method returns a particular value (when the argument list is matched).
For example:
mock.should_receive(:f).returns(12) # returns 12 mock.should_receive(:f).with(String). # returns an returns { |str| str.upcase } # upcased string
returns is an alias for and_return.
Declare that the method returns and undefined object (FlexMock.undefined). Since the undefined object will always return itself for any message sent to it, it is a good "I don‘t care" value to return for methods that are commonly used in method chains.
For example, if m.foo returns the undefined object, then:
m.foo.bar.baz
returns the undefined object without throwing an exception.
Declare that the mocked method is expected to be given a block and that the block will be called with the values supplied to yield. If the mock is called multiple times, mulitple and_yield declarations can be used to supply different values on each call.
An error is raised if the mocked method is not called with a block.
Is this expectation eligible to be called again? It is eligible only if all of its count validators agree that it is eligible.
Declare that the given method must be called in order. All ordered method calls must be received in the order specified by the ordering of the should_receive messages. Receiving a methods out of the specified order will cause a test failure.
If the user needs more fine control over ordering (e.g. specifying that a group of messages may be received in any order as long as they all come after another group of messages), a group name may be specified in the ordered calls. All messages within the same group may be received in any order.
For example, in the following, messages flip and flop may be received in any order (because they are in the same group), but must occur strictly after start but before end. The message any_time may be received at any time because it is not ordered.
m = FlexMock.new m.should_receive(:any_time) m.should_receive(:start).ordered m.should_receive(:flip).ordered(:flip_flop_group) m.should_receive(:flop).ordered(:flip_flop_group) m.should_receive(:end).ordered
Verify the current call with the given arguments matches the expectations recorded in this object.