Skip to content

Default spec_helper configuration generated by 'rspec --init' is non-intuitive

Created by: jasonkarns

The default rspec configuration block generated by rspec --init in /spec/spec_helper.rb is currently (with comments removed):

RSpec.configure do |config|
  config.treat_symbols_as_metadata_keys_with_true_values = true
  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  config.order = 'random'
end

I take issue with the defaults for two of these options: run_all_when_everything_filtered and filter_run.

Consider the scenario of someone fairly new to rspec, who runs rspec --init and begins writing their specs. As the default configuration gets them up and going, they do not modify the defaults. Everything works. They write hundreds or thousands of specs over the course of the next few months. Then, one day, they learn about tags and begin to use them to selectively run specs. Until they run the specs with a typo'd tag and the entire suite runs. WAT? No idea why that happened, but oh well. The suite still works. They continue on and keep adding various tags. Then they add a :focus tag. (Perhaps it means something special in their domain.) Now when they run rspec without arguments, only the :focus specs run. That's a serious WAT!?

Two instances where rspec takes one completely by surprise, solely because of the defaults chosen. In general, we should strive for the Principle of Least Surprise, especially with regards to default options.

I understand the utility of these two options in combination. It's great to be able to simply add :focus as a WIP tag while writing specs. However, I think they should be off by default (or simply left commented-out in the generated spec_helper).

Merge request reports