Should syntax provides another way of writing expectations.
let actual = 3
let expected = 3
actual.should.equal(expected)should and shouldNot work by being added to every object through extensions.
They can be used to define expectations on any object:
"Sleipnir".shouldNot.beEmpty()
[1, 2, 3].should.contain(3)This syntax has some known limitations.
It can not be used with custom pure swift classes, because AnyObject is a protocol and protocols can not be extended in Swift.
Both should and expect are supported and available. Using one of them or both is a matter of preference.
Values must be Equatable, Comparable or derive from NSObject.
let actual = [1, 2, 3]
actual.should.equal([1, 2, 3])
"some string".shouldNot.equal("another string")let actual : String? = nil
actual.should.beNil()
"some string".shouldNot.beNil()let actual = true
actual.should.beTrue()
actual.shouldNot.beFalse()Values must be Comparable.
3.should.beGreaterThan(1)
1.should.beLessThan(3)Values must be Comparable.
3.should.beGreaterThanOrEqualTo(1)
1.should.beLessThanOrEqualTo(3)Supports Swift collections with Equatable elements, NSArrays, NSSets and Strings.
let actual = [1, 2, 3]
actual.should.contain(1)
"some string".shouldNot.contain("another")Supports Swift collections with Equatable elements, NSArrays and Strings.
let actual = [1, 2, 3]
actual.should.beginWith(1)
"some string".should.endWith("string")"".should.beEmpty()
[1,2,3].shouldNot.beEmpty()