cucumber: RSpec::Expectations::ExpectationNotMetError: expected true to respond to `true?`

2.6k views Asked by At

According the answer I can use the rspec expectation form with the .

value = true
expect(value).to be_a(TrueClass) # => true

but if I use #be_true method it refused answering with exception:

expect(true).to be_true # => RSpec::Expectations::ExpectationNotMetError: expected true to respond to `true?`

So I can't use the method like I've used it in rails but without rails itself. So question is how can I add the methods not including the rails, and not defining them manually?

1

There are 1 answers

2
Dana Scheider On BEST ANSWER

Try like this:

expect(true).to be true

Although the RSpec documentation indicates be_true will pass if the object is not nil or false, in practice I find it does not pass if the object is true. If you want to check that the value is true specifically, and not just a truthy value, you need to use be true, (with the space), eql true, eq true, equal true, etc.

(If you're not already familiar, you can read about the difference between RSpec's equality matchers here. You don't say which RSpec version you're using, so that applies to 3.2 and I believe this is the same for other versions.)