Skip to content

Instantly share code, notes, and snippets.

@fables-tales
Created October 21, 2014 09:29
Show Gist options
  • Save fables-tales/9da4777150cf958ba5b9 to your computer and use it in GitHub Desktop.
Save fables-tales/9da4777150cf958ba5b9 to your computer and use it in GitHub Desktop.
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
@fables-tales
Copy link
Author

@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