Matcher be_true ruby / rspec

1

I'm starting to study about ruby / rspec following a book, but I'm not making progress using matcher be_true .

The following is the error:

BagOfWords#push is possible to put words on it (FAILED - 1)

Failures:

1) BagOfWords#push is possible to put words on it
  Failure/Error: expect(isTrue).to be_true
    expected true to respond to 'true?'
  # ./spec/bag_of_words_spec.rb:12:in 'block (3 levels) in <top (require d)>'

Finished in 0.015 seconds (files took 0.54403 seconds to load)  
1 example, 1 failure

Failed examples:

rspec ./spec/bag_of_words_spec.rb:7 # BagOfWords#push is possible to put words on it
    
asked by anonymous 22.10.2014 / 02:21

2 answers

1

According to this thread , matchers be_true and be_false have been replaced with be_truthy and be_falsey . You can still use be true and be false (note that they are separate).

The difference between be true and be_truthy is that a test using be_truthy will pass if the object is not nil . The inverse happens to be false and be_falsey .

From official documentation , we have:

expect(objeto).to be_truthy   # passa se o objeto não for nil ou false
expect(objeto).to be true     # passa somente se o objeto for true
expect(objeto).to be_falsy    # passa se o objeto for nil ou false
expect(objeto).to be false    # passa somente se o objeto for false

Examples

it { expect(true).to be true }        # passa
it { expect("string").to be true }    # falha
it { expect(nil).to be true }         # falha
it { expect(false).to be true }       # falha

it { expect(false).to be false }      # passa
it { expect("string").to be false}    # falha
it { expect(nil).to be false}         # falha
it { expect(true).to be false}        # falha
    
24.10.2016 / 15:33
0

Answer: Which version of RSpec are you using? You can try to use be_truthy if it is RSpec 3. - @Bruno dos Santos

    
12.11.2014 / 00:22