Junior Track Roadmap

RSpec matchers: expect

This course covers RSpec expectations as this app's suite writes them. It starts with the expect(actual).to matcher wiring and its .not_to form. It then reads matchers from RSpec's installed source: eq compares with plain Ruby ==, include delegates to the value's own include?, and be_truthy follows Ruby's truthiness rule. The block form shows why change and raise_error need expect with a block. A field guide covers predicate matchers, have_http_status, redirect_to, contain_exactly and chaining with .and. A final lesson ties the matchers together.

What you'll learn

  • ✓How expect, .to and .not_to connect a value to a matcher
  • ✓Why eq uses plain Ruby == and include delegates to include?
  • ✓How be_truthy, be_falsey and be_nil follow Ruby's truthiness
  • ✓Why change and raise_error need the block form of expect
  • ✓How be_xxx predicate matchers and rspec-rails request matchers work
  • ✓How to chain matchers with .and and use contain_exactly
Free preview · Lesson 1 2 min read

expect(actual).to matcher: wrapping a value, describing what it should be

The course right before this one, RSpec: describe/context/it, showed the outer shape: describe, context and it, the blocks that organize a test and name what it checks. Inside every it block sits the assertion itself, and this app's spec/services/identity/account_update_service_spec.rb has a clean…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...