Search code examples
ruby-on-railsrubyrspec2rspec-rails

Define stub/mock expectation/should_receive in one line?


Anyone know of a way to shorten this to one line? (RSpec 2)

location = mock
location.should_receive(:build)

For example, you can define the following:

location = stub
location.stub(build: true)

The above is the same as:

location = stub(build :true)

So, anyone see a way to specify an expectation in the mock call?


Solution

  • location = mock.tap { |loc| loc.should_receive(:build) }