Junior Track Roadmap

Testing: shared examples

This course covers RSpec shared examples, starting from duplication in this app's request specs. A login-redirect assertion appears, typed by hand, in several files. RSpec's installed source shows how shared_examples stores a named block for later evaluation. It also shows how it_behaves_like wraps that block in a nested example group, while include_examples evaluates it flat in the current group. Later lessons cover arguments, customization blocks, an admin-only guard that has drifted, and a plain-Ruby challenge that builds a miniature registry.

What you'll learn

  • ✓How shared_examples stores a named block and how scope decides where it can be found
  • ✓How it_behaves_like creates a nested example group labeled "behaves like"
  • ✓How include_examples and include_context evaluate shared content directly in the current group
  • ✓Passing arguments and a customization block into a shared example
  • ✓Finding duplicated assertions in a spec suite, including ones that have drifted apart
  • ✓The ArgumentError raised when a shared example name is not registered
Free preview · Lesson 1 3 min read

The duplication this app's spec suite already has

spec/requests/execution_spec.rb:

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...