Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Way to Test Boolean Values in Rspec

Looking to get some opinions here.

What is the best way to check boolean values with RSPEC I have seen it done a few different ways:

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

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

like image 679
Matthew Avatar asked Aug 16 '11 18:08

Matthew


1 Answers

Here's 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

Which basically means that if you only care if a value evaluates to true then you want to use == true

like image 61
solnic Avatar answered Oct 25 '22 00:10

solnic