Reputation: 40277
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?
Upvotes: 1
Views: 447
Reputation: 21791
If every your test has mock definition, you can shorten the notation by using let in the beginning of file.
let (:location) { double :location }
Then every time when you're using location
, it automatically creates new mock object:
location.should_receive(:build)
Upvotes: 1
Reputation: 648
Looks ugly, though works:
(location = mock).should_receive(:build)
Upvotes: 1