-
Notifications
You must be signed in to change notification settings - Fork 14
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
Issue24 eachall keys #35
base: master
Are you sure you want to change the base?
Changes from 2 commits
d0a1298
b3fc462
92fb307
c1d3bca
930af32
87a6877
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,14 @@ | |
describe "using all()", -> | ||
|
||
describe "an object without length", -> | ||
nonLengthObject = {} | ||
nonLengthObject = 1 | ||
|
||
it "fails to have all elements equal to 1", -> | ||
(() -> nonLengthObject.should.all.equal 1). | ||
should.throw "expected {} to have a property 'length'" | ||
|
||
it "fails not to have all elements equal to 1", -> | ||
it "fails to have all elements equal to assertion", -> | ||
(() -> nonLengthObject.should.all.equal 1). | ||
should.throw "expected {} to have a property 'length'" | ||
|
||
should.throw "since length property unavailable: expected 1 to be an object" | ||
it "fails not to have all elements equal to assertion", -> | ||
(() -> nonLengthObject.should.not.all.equal 1). | ||
should.throw "since length property unavailable: expected 1 to be an object" | ||
|
||
describe "an object without numeric length", -> | ||
nonNumLengthObject = { length: 'a' } | ||
|
@@ -35,6 +33,15 @@ describe "an empty array's elements", -> | |
it "should trivially all not equal 1", -> | ||
emptyArray.should.all.not.equal(1) | ||
|
||
describe "an empty object's elements", -> | ||
emptyObject = {} | ||
|
||
it "should trivially all equal 1", -> | ||
emptyObject.should.all.equal(1) | ||
|
||
it "should trivially all not equal 1", -> | ||
emptyObject.should.all.not.equal(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this should fail before asserting equality on any keys. It's empty. |
||
|
||
|
||
describe "the array [1, 1]'s elements", -> | ||
array = [1, 1] | ||
|
@@ -67,6 +74,37 @@ describe "the array [1, 1]'s elements", -> | |
(() -> array.should.not.all.not.equal 2). | ||
should.throw "expected not all elements of [ 1, 1 ] to not equal 2" | ||
|
||
describe "the object {first: 1, second: 1}'s elements", -> | ||
obj = [1, 1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this meant to be an object literal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dang, yes |
||
|
||
it "should all equal 1", -> | ||
obj.should.all.equal 1 | ||
|
||
it "should all not equal 2", -> | ||
obj.should.all.not.equal 2 | ||
|
||
it "should not all equal 2", -> | ||
obj.should.not.all.equal 2 | ||
|
||
it "should not all not equal 1", -> | ||
obj.should.not.all.not.equal 1 | ||
|
||
it "do not all equal 2", -> | ||
(() -> obj.should.all.equal 2). | ||
should.throw "expected all elements of [ 1, 1 ] to equal 2" | ||
|
||
it "do not all *not* equal 1", -> | ||
(() -> obj.should.all.not.equal 1). | ||
should.throw "expected all elements of [ 1, 1 ] to not equal 1" | ||
|
||
it "do not *not* all equal 1", -> | ||
(() -> obj.should.not.all.equal 1). | ||
should.throw "expected not all elements of [ 1, 1 ] to equal 1" | ||
|
||
it "do not *not* all not equal 2", -> | ||
(() -> obj.should.not.all.not.equal 2). | ||
should.throw "expected not all elements of [ 1, 1 ] to not equal 2" | ||
|
||
|
||
describe "the array [1, 2]'s elements", -> | ||
array = [1, 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.
This seems a bit broken. I would think that an empty object should fail at
.all
as it has no keys.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.
While I would agree...
It is currently the default behaviour, see master at test/all.coffee does:
I considered it a breaking change to modify this behaviour.
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.
Okay fair enough. We'll change this in a breaking release later on then 😄
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.
Just as a note, all should pass if the array is empty.
If it was to fail, then it's negation would have to be true. The negation of all is 'some are not', so an empty array would have to return true if some of its elements are 'not'. However, you cannot find an element in the empty set that is 'not; so it should be false; this is definitely not be behavior you want in a some statement.
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.
james, were you recommending that the some statements were not behaving as expected?
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.
No, I'm confirming that an empty array should return true if you check to see if all of its elements are equal to 1. This is logic 101.