Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created August 5, 2014 15:31
Show Gist options
  • Save lukeredpath/cae3033ef0c754937b69 to your computer and use it in GitHub Desktop.
Save lukeredpath/cae3033ef0c754937b69 to your computer and use it in GitHub Desktop.
Rspec mock argument capture
# just an example of what it could be
argument = capture('label')
widget = double
# argument acts like an argument matcher that always matches but stores a reference to the real value
allow(widget).to receive(:do_something).with(argument)
# contrived, I know this could be done using the instance_of argument matcher
expect(argument.value).to be_instance_of(Something)
@gbirchmeier
Copy link

expect(foo).to receive(:publish_doc) do |doc|
  expect(doc.category).to eq "Code red"
  expect(doc.message).to eq "The monkeys have escaped"
end

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