-
-
Save aaronjensen/2019573 to your computer and use it in GitHub Desktop.
Revisions
-
aaronjensen revised this gist
Mar 12, 2012 . 2 changed files with 41 additions and 23 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ require 'rspec' # is it really this simple? RSpec::Matchers.define :have_received do |method_name| match do |actual| @args ||= [] @method_name ||= method_name actual.received_message?(@method_name, *@args) end def with(*args) @args = args self end end describe 'have received matcher' do let(:foo) { stub.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).with('home') end it 'works with should_not' do foo.should_not have_received :go end # fails it 'works on already stubbed methods' do foo.stub :go => true foo.go foo.should have_received :go end end 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +0,0 @@ -
RobinClowers revised this gist
Mar 12, 2012 . 1 changed file with 8 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ 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 @@ -15,4 +15,9 @@ describe 'have received matcher' do foo.should have_received :go end it 'matches arguments' do foo.go 'home' foo.should have_received(:go, 'home') end end -
RobinClowers created this gist
Mar 11, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ require 'rspec' # is it really this simple? RSpec::Matchers.define :have_received do |expected| match do |actual| actual.received_message? expected 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 end