Skip to content
Arctic Fox edited this page May 3, 2019 · 1 revision

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

be

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.

Syntax

be

Examples

expect(true).to be  # true
expect(5).to be     # true
expect(false).to be # false
expect(nil).to be   # false

be_true

Checks if a value is equal to true.

Syntax

be_true

Examples

expect(true).to be_true  # true
expect(5).to be_true     # false
expect(false).to be_true # false
expect(nil).to be_true   # false

be_truthy

Checks if something is not false and not nil.

Syntax

be_truthy

Examples

expect(true).to be_truthy  # true
expect(5).to be_truthy     # true
expect(false).to be_truthy # false
expect(nil).to be_truthy   # false

be_false

Checks if value equals false.

Syntax

be_false

Examples

expect(true).to be_false  # false
expect(5).to be_false     # false
expect(false).to be_false # true
expect(nil).to be_false   # false

be_falsey

Checks if something is false or nil.

Syntax

be_falsey

Examples

expect(true).to be_falsey  # false
expect(5).to be_falsey     # false
expect(false).to be_falsey # true
expect(nil).to be_falsey   # true

be_nil

Checks if something is nil.

Syntax

be_nil

Examples

expect(true).to be_nil  # false
expect(5).to be_nil     # false
expect(false).to be_nil # false
expect(nil).to be_nil   # true

Truth Table

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
Clone this wiki locally