Skip to content

Instantly share code, notes, and snippets.

@RobinClowers
Created March 11, 2012 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RobinClowers/2018620 to your computer and use it in GitHub Desktop.
Save RobinClowers/2018620 to your computer and use it in GitHub Desktop.
Rspec mock AAA extension
require 'rspec'
# is it really this simple?
RSpec::Matchers.define :have_received do |method_name, *args|
match do |actual|
actual.received_message?(method_name, *args, &block)
end
end
describe 'have received matcher' do
let(:foo) { double.as_null_object }
it 'allows arrange, act, assert syntax' do
foo.go
foo.should have_received :go
end
it 'matches arguments' do
foo.go 'home'
foo.should have_received(:go, 'home')
end
end
@aaronjensen
Copy link

Looks like it hooks up to method_missing, so it will only work on spies or things that are unstubbed. I made some changes and included a failing test: https://gist.github.com/2019573

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