Skip to content

Instantly share code, notes, and snippets.

@smazhara
Created June 6, 2012 18:38
Show Gist options
  • Save smazhara/2883805 to your computer and use it in GitHub Desktop.
Save smazhara/2883805 to your computer and use it in GitHub Desktop.
rspec's should_receive with implicit subject
» rspec string_spec.rb
F
Failures:
1) String
Failure/Error: it { should_receive(:size) }
(#<RSpec::Core::ExampleGroup::Nested_1:0x000000013e67b8>).size(any args)
expected: 1 time
received: 0 times
# ./string_spec.rb:4:in `block (2 levels) in <top (required)>'
Finished in 0.00091 seconds
1 example, 1 failure
Failed examples:
rspec ./string_spec.rb:4 # String
describe String do
subject { "asdf" }
after { subject.size }
it { should_receive(:size) }
end
@smazhara
Copy link
Author

smazhara commented Jun 6, 2012

Example showing unexpected spec failure as should_receive is not respecting implicit subject. This passes with explicit subject: subject.should_receive(:size)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment