Read more

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

Henning Koch
January 28, 2016Software engineer at makandra GmbH

be_true and be_false were removed form RSpec 3.

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 Show archive.org snapshot .

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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:

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

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

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

See also

RSpec claims nil to be false

Posted by Henning Koch to makandra dev (2016-01-28 11:38)