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.
Observation matchers - Ruby Tutorial
From the course: Ruby: Testing with RSpec
Observation matchers
- Observation Matchers allow us to create expectations about how things change. We can observe how objects change, how values change, watch for errors, or watch for output. The syntax we've been using for expectations so far has been we expect ( ).to( ) We're passing in arguments to both expect and in to. Starting with observation matchers we're gonna use a different form of this. We're gonna use expect { }. to ( ) Notice there we've got the curly braces, that represents a block of code that we're passing in, not an argument. Let's see how we use this new syntax to observe a change in an object's attributes. Let's say that we have an empty array. I can create an expectation that says expect { array <<1 }. to change(array, :empty?).from(true).to(false) Notice here that our new matcher is change. Change takes two arguments. The first one is an object that's an instance that we can work with. Then the second argument is the attribute or the method that we wanna call on that object. After…
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)
-
-
-
-
-
-
-