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

Parts of an Expectation

When you see an expectation like the following one:

 expect​(deck.cards.count).to eq(52), ​'not playing with a full deck'

…you’ll notice several forms of punctuation in use: parentheses, dots, and whitespace. While there’s some variety here, the syntax consistently uses just a few simple parts:

  • A subject—the thing you’re testing—that is, an instance of a Ruby class

  • A matcher—an object that specifies what you expect to be true about the subject, and provides the pass/fail logic

  • (optionally) A custom failure message

These parts are held together with a bit of glue code: expect, together with either the to or not_to method.

Let’s get a feel for how these parts ...

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