Skip to content

Instantly share code, notes, and snippets.

@Nerian
Created February 13, 2014 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nerian/8973192 to your computer and use it in GitHub Desktop.
Save Nerian/8973192 to your computer and use it in GitHub Desktop.
class MyTestClass
def cucu
tra(1)
tra(2)
end
def tra(args)
end
end
it "expect on the second", :focus do
ob = MyTestClass.new
expect(ob).to receive(:tra).with(2)
ob.cucu
end
@thomas-holmes
Copy link

The best I can think of is this:

expect(ob).to receive(:tra).ordered
expect(obj).to receive(:tra).with(2).ordered

Expectations have to be evaluated in order. If you do the above it will catch the first call to tra regardless of the args and then expect another call to tra with 2 as the arg.

@cupakromer
Copy link

Not sure if you'll see this, but if you do, you can create a "catch-all":

it "expect on the second", :focus do
  ob = MyTestClass.new

  allow(ob).to receive(:tra)  # catch all

  expect(ob).to receive(:tra).with(2)
  ob.cucu
end

I wrote a series on RSpec method matching:

@Nerian
Copy link
Author

Nerian commented Feb 17, 2014

Thanks guys!

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