From the course: Ruby: Testing with RSpec

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Truthiness matchers

Truthiness matchers - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Truthiness matchers

- In this movie, we're gonna take a look at the second type of RSpec matchers which are Truthiness Matchers. That is a matcher than can determine whether something is true or false. The simplest way to use a truthiness matcher in an expectation is just to say that you expect something to be true. Three separate words, two, space, be, space, true, and that's because true is actually being passed in as an argument to the be matcher. As you saw briefly in the last movie the be matcher is an alias for that object equivalence. All right, the object identity. To say that something is exactly the same. It turns out that inside Ruby whenever it evaluates something and it turns out to be true or false it turns it into that same object. There's a true object and there's a false object. And it uses that same object ID no matter what expression is resolving to true or false. Therefore this does match. And we can do the same thing with false. If we have 1 is greater than 2, we know that's false…

Contents