Best way to test boolean values ​​in rspec

Looking to get some opinions here.

What is the best way to validate boolean values ​​with RSPEC. I saw how this was done in several ways:

myvar.should == true myvar.should be true myvar.should be 

Also, I usually only care about the value of the duck, that is, if it evaluates to true / false, I don't care what its actual value is ...

+7
source share
3 answers

Here is the difference between "== true" and "be (true)":

 describe true do it { should be(true) } it { should be_true } end describe 'true' do it { should_not be(true) } it { should be_true } end 

This basically means that if you don't care if the value evaluates to true, you want to use == true

+13
source

I ended up doing the opposite logic:

 expect([true, false]).to include myvar 
+3
source

In my advice, it is best to add rspec_boolean to your Gemfile in the group: development ,: test:

gem 'rspec_boolean'

And how to use it as:

expect (val.is_something?). be_boolean

0
source

All Articles