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

Your First Spec

Rather than testing some intricate production system, let’s imagine something a little more concrete: a sandwich. Yes, it’s silly, but it’ll keep the examples short—plus, we were hungry while writing this chapter.

What’s the most important property of a sandwich? The bread? The condiments? No, the most important thing about a sandwich is that it should taste good. Let’s say so using the language of RSpec.

RSpec uses the words describe and it to express concepts in a conversational format:

  • “Describe an ideal sandwich”
  • “First, it is delicious”

Create a new project directory, with a subdirectory called spec. Inside «your_project»/spec, create a file called sandwich_spec.rb with the following contents:

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