Created
August 5, 2014 15:31
-
-
Save lukeredpath/cae3033ef0c754937b69 to your computer and use it in GitHub Desktop.
Rspec mock argument capture
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
# 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) |
@myronmarston nope, that's all thats needed, I wasn't aware you could yield the argument.
Still, I like the capture syntax :)
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
You can already do this:
It's unclear to me what's better about
capture
then the flexibility you already get from being able to pass a block?