Created
March 11, 2012 23:19
-
-
Save RobinClowers/2018620 to your computer and use it in GitHub Desktop.
Rspec mock AAA extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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