February 2013
Intermediate to advanced
272 pages
5h 45m
English
The should method makes for nice, readable expectations. But it has a downside: it doesn’t play well with unconventional Ruby objects like delegates.[289]
For these cases, RSpec supports a similar notation called expect that isn’t subject to these limitations.
| rspec/expect.rb | |
| | expect(2 + 2).to == 4 |
Here are a few of the examples from earlier that have been adapted to use expect:
| rspec/expect.rb | |
| | expect(2 + 2).not_to == 5 |
| | expect(2 + 2).to be > 3 |
| | |
| | expect('hello').to =~ /ell/ |
| | expect(some_object).to be_festive |
| | |
| | expect { |
| | SomeNonExistentClass.new |
| | }.to raise_error(NameError) |
| | |
| | expect(this_book).to please('developers') |
While Cucumber works well with rspec-expectations, you’re certainly not required to use it. If you don’t ...
Read now
Unlock full access