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:
Get Effective Testing with RSpec 3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.