In this chapter, you practiced several good testing habits related to running your specs. RSpec’s support for these habits sets it apart from other test frameworks:
Powerful formatters show your specs’ output in a variety of ways.
Filtering your examples lets you focus on a specific issue and run just the specs you need.
The pending method helps you sketch out examples before implementing the behavior fully.
Now, you’re going to experiment with these techniques a little further.
In a new directory, create a file called spec/tea_spec.rb with the following contents:
| class Tea |
| end |
| |
| RSpec.configure do |config| |
| config.example_status_persistence_file_path = 'spec/examples.txt' |
| end |
| |
| RSpec.describe Tea do |
| let(:tea) { Tea.new } |
| |
| it 'tastes like Earl Grey' do |
| expect(tea.flavor).to be :earl_grey |
| end |
| |
| it 'is hot' do |
| expect(tea.temperature).to be > 200.0 |
| end |
| end |
Run bare rspec once so it can record the status of the examples; then run RSpec with the --next-failure flag and look at the output. How does it differ from that of the --only-failures technique we discussed in Rerunning Everything That Failed?
Implement the Tea class’s flavor method to make it pass the first example. Now, run RSpec again with the same --next-failure flag. What do you see?
Before finishing the implementation, try out the different formatters. Run rspec --help to see a list of built-in output formats. Try the ones we haven’t covered in this chapter. When you get to HTML, open the page in your browser and see how RSpec renders passing and failing specs.
With the help of the --next-failure flag, implement the rest of the Tea class. Now, pour yourself a cup of your favorite hot beverage. You’ve earned it!