O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Rails Matchers Cheat Sheet

In addition to these spec types, rspec-rails provides some Rails-specific matchers. Some of these are available to any spec once you’ve required rails_helper; others are just for certain spec types.

MatcherPasses if…Available in…

be_a_new(model_class)

record.is_a(model_class) && record.new_record?

All spec types

be_a_new(model_class).with(attribute: ’value’)

record.is_a(model_class) && record.new_record? && record.attribute == ’value’

All spec types

be_new_record

record.new_record?

All spec types

be_valid

record.valid?

All spec types

have_been_enqueued.with(some_args)

Job was enqueued with matching arguments

All spec types

have_enqueued_job(job_class).with(some_args), enqueue_job(job_class).with(some_args)

Code in an expect block ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required