-
Notifications
You must be signed in to change notification settings - Fork 5
Truthy Matchers
Truthy matchers test whether something is true or not.
"Falsey" means something is false
or nil
.
"Truthy" is the opposite of falsey, which means it is not false
and not nil
.
In other words, a "truthy" value will satisfy an if-statement in Crystal,
while a "falsey" one will not satisfy an if-statement.
See Crystal Truthy and Falsey Values for more info.
be | be_true | be_truthy | be_false | be_falsey | be_nil
Checks if something "is." It's very philosophical. This matcher simply tests if a value is truthy. It's a slightly shorter way to write be_truthy. It does exactly the same thing.
be
expect(true).to be # true
expect(5).to be # true
expect(false).to be # false
expect(nil).to be # false
Checks if a value is equal to true
.
be_true
expect(true).to be_true # true
expect(5).to be_true # false
expect(false).to be_true # false
expect(nil).to be_true # false
Checks if something is not false
and not nil
.
be_truthy
expect(true).to be_truthy # true
expect(5).to be_truthy # true
expect(false).to be_truthy # false
expect(nil).to be_truthy # false
Checks if value equals false
.
be_false
expect(true).to be_false # false
expect(5).to be_false # false
expect(false).to be_false # true
expect(nil).to be_false # false
Checks if something is false
or nil
.
be_falsey
expect(true).to be_falsey # false
expect(5).to be_falsey # false
expect(false).to be_falsey # true
expect(nil).to be_falsey # true
Checks if something is nil
.
be_nil
expect(true).to be_nil # false
expect(5).to be_nil # false
expect(false).to be_nil # false
expect(nil).to be_nil # true
Matcher | true | false | nil | truthy |
---|---|---|---|---|
be | true | false | false | true |
be_true | true | false | false | false |
be_truthy | true | false | false | true |
be_false | false | true | false | false |
be_falsey | false | true | true | false |
be_nil | false | false | true | false |