Running Just What You Need

In the examples in this chapter, we’ve always run all the specs together. On a real project, you don’t necessarily want to load your entire test suite every time you invoke RSpec.

If you’re diagnosing a specific failure, for instance, you’ll want to run just that one example. If you’re trying to get rapid feedback on your design, you can bypass slow or unrelated specs.

The easiest way to narrow down your test run is to pass a list of file or directory names to rspec:

 $ ​​rspec​​ ​​spec/unit​​ # Load *_spec.rb in this dir and subdirs
 $ ​​rspec​​ ​​spec/unit/specific_spec.rb​​ # Load just one spec file
 $ ​​rspec​​ ​​spec/unit​​ ​​spec/smoke​​ # Load more than one directory
 $ ​​rspec​​ ​​spec/unit​​ ​​spec/foo_spec.rb ...

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.