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 - Ruby Tutorial
From the course: Ruby: Testing with RSpec
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Fundamentals3m 48s
-
(Locked)
A deprecated modifier: should4m 19s
-
Equivalence matchers7m 3s
-
(Locked)
Truthiness matchers5m 41s
-
(Locked)
Numeric comparison matchers3m 32s
-
(Locked)
Collections6m 13s
-
(Locked)
Other useful matchers7m 44s
-
(Locked)
Predicate matchers5m 14s
-
(Locked)
Observation matchers10m 36s
-
(Locked)
Complex expectations10m 43s
-
(Locked)
-
-
-
-
-
-
-