From the course: Ruby: Testing with RSpec
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Predicate matchers - Ruby Tutorial
From the course: Ruby: Testing with RSpec
Predicate matchers
- In this movie, we'll learn about RSpec's Predicate Matchers. These are different from the Matchers that we've seen so far. That's because there's not a finite set of Matchers to learn. The Matchers themselves are dynamically defined. Let me show you what I mean. In Ruby, there are a number of methods built in for asking questions of objects. And they all end in a question mark. So for example, value.nil? will return true if the value is nil, or false if it's not. And the same thing is true for odd, even, zero, nonzero, integer, or empty. All of those allow us to ask a question of the object. And they all end in a question mark. It's a common Ruby idiom. RSpec allows us to work with these using predicate matchers. So instead of nil?, we can have a matcher, which is be_nil. We actually saw that in a previous movie. But the same thing is true for all of those other ones. We simply remove the question mark, and add be_ to the front of it. So we can expect(value).to be_odd, or…
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)
-
-
-
-
-
-
-