Posted over 2 years ago. Visible to the public. Repeats.

RSpec: be_true does not actually check if a value is true

Don't use be_true to check if a value is true. It actually checks if it anything other than nil or false. That's why it has been renamed to be_truthy in recent RSpec versions.

The same thing holds for be_false, which actually checks if a value is not "truthy".

If you want to check for true or false in RSpec 2, write this instead:

Copy
value.should == true value.should == false

If you want to check for true or false in RSpec 3+, write this instead:

Copy
expect(value).to eq(true) expect(value).to eq(false)

See also

RSpec claims nil to be false

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Henning Koch
Last edit:
over 2 years ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more