Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for multiple captor invocations #144

Merged
merged 2 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/matchers/captor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ module.exports = ->
capture: create
name: 'captor.capture'
matches: (matcherArgs, actual) ->
if not captor.values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try captor.values ||= [] and see if that works for you here to save a line

captor.values = []
captor.values.push actual
captor.value = actual
return true

8 changes: 8 additions & 0 deletions test/src/captor-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,13 @@ describe 'argument captors (a special sub-type of matchers)', ->
Given -> @testDouble("SHIRTS!")
When -> td.verify(@testDouble(@captor.capture()))
Then -> @captor.value == "SHIRTS!"
And -> expect(@captor.values).to.deep.eq ["SHIRTS!"]

describe 'when verifying multiple', ->
Given -> @testDouble("SHIRTS!")
And -> @testDouble("SHIRTS AGAIN!")
When -> td.verify(@testDouble(@captor.capture()))
Then -> @captor.value == "SHIRTS AGAIN!"
And -> expect(@captor.values).to.deep.eq ["SHIRTS!", "SHIRTS AGAIN!"]