-
Notifications
You must be signed in to change notification settings - Fork 29
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
Feature/spy call order by parameter #75
Feature/spy call order by parameter #75
Conversation
Good job! |
Thank you @stalniy! Looking forward to contribute. Regards |
This is looking good so far. I'd also like to see some tests that address partial arguments - for example what do these do? spy(1,2,3)
spy(3,4,5)
// These should definitely pass - let's see tests for that
expect(spy).first.to.be.called.with(1,2,3)
expect(spy).second.to.be.called.with(3,4,5)
expect(spy).first.to.be.called.with.exactly(1,2,3)
expect(spy).second.to.be.called.with.exactly(3,4,5)
// These should definitely fail - let's see tests for that
expect(spy).first.to.be.called.with(3,4,5)
expect(spy).second.to.be.called.with(1,2,3)
expect(spy).first.to.be.called.with.exactly(1)
expect(spy).first.to.be.called.with.exactly(2)
expect(spy).first.to.be.called.with.exactly(3)
expect(spy).second.to.be.called.with.exactly(3)
expect(spy).second.to.be.called.with.exactly(4)
expect(spy).second.to.be.called.with.exactly(5)
// These should definitely pass - let's see tests for that
expect(spy).first.to.not.be.called.with(3,4,5)
expect(spy).second.to.not.be.called.with(1,2,3)
expect(spy).first.to.not.be.called.with.exactly(1)
expect(spy).first.to.not.be.called.with.exactly(2)
expect(spy).first.to.not.be.called.with.exactly(3)
expect(spy).second.to.not.be.called.with.exactly(3)
expect(spy).second.to.not.be.called.with.exactly(4)
expect(spy).second.to.not.be.called.with.exactly(5)
// Should these all pass? My intuition says yes
expect(spy).first.to.be.called.with(2)
expect(spy).first.to.be.called.with(2,3)
expect(spy).first.to.be.called.with(1)
expect(spy).first.to.be.called.with(1,2)
expect(spy).second.to.be.called.with(3,4)
expect(spy).second.to.be.called.with(4,5)
expect(spy).first.to.be.called.with(3)
expect(spy).second.to.be.called.with(3)
// Should these all fail? My intuition says yes
expect(spy).first.to.not.be.called.with(2)
expect(spy).first.to.not.be.called.with(2,3)
expect(spy).first.to.not.be.called.with(1)
expect(spy).first.to.not.be.called.with(1,2)
expect(spy).second.to.not.be.called.with(3,4)
expect(spy).second.to.not.be.called.with(4,5)
expect(spy).first.to.not.be.called.with(3)
expect(spy).second.to.not.be.called.with(3) |
Hello @keithamus I would like to have a good definition of
At this moment, I am receiving The first part is actually covered as all the tests without exactly pass or fail as expected. I will update the PR to fit spec 2, this should only require:
Regards |
Sorry yeah, I forgot the syntax - it should be |
@keithamus Sorry for the delay, I had a complicated week. I just added first, second, third and nth with.exactly assertions. This is the thing I found about your last post:
This open my mind to a |
test/spies.js
Outdated
@@ -357,47 +434,65 @@ describe('Chai Spies', function () { | |||
}); | |||
}); | |||
|
|||
describe('.always.with.exactly(arg, ...)', function () { | |||
it('should pass when called with an argument', function () { | |||
describe('.nth(...).with.exactly(arg, ...)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious here why always.with.exactly
tests have been removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, seems I accidentally replaced those tests. I will be restoring them.
Tests appearently lost, restored. I apologize about that :) |
Hello, are there any news on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @cnexans - missed the last notification. This all looks great to me! As it's a big change I'd like @stalniy to take a look and merge it if good, but it's a LGTM from me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good, I'd like @cnexans to fix few minor bugs related to documentation and error messages
test/spies.js
Outdated
spy(1); | ||
spy(2); | ||
spy.should.have.been.first.called.with(1); | ||
spy.should.not.have.been.first.called.with(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant. Assertion below covers this case
test/spies.js
Outdated
var spy = chai.spy(); | ||
spy(1); | ||
spy(2); | ||
spy.should.have.not.been.second.called.with(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant. Covered by assertions below
test/spies.js
Outdated
spy(0); | ||
spy(1); | ||
spy(2); | ||
spy.should.have.not.been.third.called.with(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant. The same reason
README.md
Outdated
```js | ||
spy('foo'); | ||
spy('bar'); | ||
expect(spy).to.have.been.first.called.with('baz'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be to.have.been.THIRD.called
as you then say that spy has not been called third time.
lib/spy.js
Outdated
new Assertion(this._obj).to.be.have.been.called.min(nthCall); | ||
this.assert( | ||
nthCallWith(spy, nthCall - 1, expArgs) | ||
, 'expected ' + this._obj + ' to have been called at the ' + ordinalNumber + ' time with #{exp} but got ' + actArgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actArgs
is an array, if so then better to use #{act}
and pass 5th argument in this.assert
lib/spy.js
Outdated
new Assertion(this._obj).to.be.have.been.called.min(nthCall); | ||
this.assert( | ||
_.eql(actArgs, args) | ||
, 'expected ' + this._obj + ' to have been called at the ' + ordinalNumber + ' time with exactly #{exp} but got ' + args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here I guess args
can be an array of objects and if so, then you will have not well formatted error messages
@cnexans do you have time to fix this? |
Hi @stalniy I'm sorry I've been busy these days. I'll be fixing this next days and report back to you |
@cnexans any progress? update: feature is almost done it'd be good to merge it soon! |
287657b
to
3d2ba5e
Compare
3d2ba5e
to
4b1661c
Compare
@cnexans @keithamus I fixed the issues and squashed commits into one. So, now it looks good and can be merged. By the way found a bug with incorrect arguments call comparison. Fixed that as well :) |
#59
Adds the following assertions
Regards