Created
October 21, 2014 09:29
-
-
Save fables-tales/9da4777150cf958ba5b9 to your computer and use it in GitHub Desktop.
This file contains 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
def bar | |
puts "welp" | |
end | |
def foo | |
bar | |
end | |
RSpec.describe "foo" do | |
it "calls bar" do | |
expect(self).to receive(:bar) | |
foo | |
end | |
end |
@itgsoddabe the double is a different object, so it doesn't receive anything. If you want to use the have_received
style of expectation you'd do this:
allow(self).to receive(:sum)
average(numbers: [3,5,2])
expect(self).to have_received(:sum).with (numbers: [3,5,2])
If you do want to use the double you could also do this:
s = double()
s.average(numbers: [3,5,2])
expect(s).to have_received(:sum).with (numbers: [3,5,2])
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, thanks! it worked.
I had tried the following:
But that failed with
Failure/Error: expect(s).to have_received(:sum).with(numbers: [3,5,2]) Double #<RSpec::ExampleGroups::Average:0x007fa281b1dbd8 @__memoized=nil> expected to have received sum, but that object is not a spy or method has not been stubbed.