...

/

Running Smaller Groups of Tests: RSpec

Running Smaller Groups of Tests: RSpec

Learn RSpec metadata and how we can run RSpec smaller groups of tests.

RSpec running smaller groups of tests

We recommend using the rspec command directly rather than going through any rake tasks that RSpec defines because it’s a bit faster. The rspec command can take one or more arguments: files, directories, or file globs. For file globs, all matching files are run the following way:

Terminal 1
Terminal
Loading...

RSpec makes it easy to run a single spec. All we need to do is add the line number to the file along with a colon:

Press + to interact
$ bundle exec rspec spec/models/task_spec.rb:5

RSpec has a less user-friendly syntax that identifies the tests by their place within each nested block. This version is more robust against adding lines to tests and is what some RSpec tools (like bisect) will output:

Press + to interact
$ bundle exec rspec spec/models/task_spec.rb[1:1:1]

When RSpec’s default formatter runs, RSpec will place the file name and line number of each failing test at the end of the output, ...