Basics

As the name implies, this library is part of the RSpec testing framework. However, you don’t need the rest of RSpec to use it; you can install rspec-expectations as a stand-alone gem.

 
$ ​gem install rspec-expectations

The premise behind rspec-expectations is that test assertions should read like spoken sentences. The library adds a should method to every Ruby object so that instead of writing assert(2 + 2 == 4), you can write readable code like this:

rspec/examples.rb
 
(2 + 2).should == 4

If the condition holds true, your Cucumber step will pass. If the condition is false, Cucumber will report a failure.

rspec-expectations comes with a number of matchers—these are different ways to use should (and its counterpart, should_not, which ...

Get Cucumber Recipes 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.