According to pronounced James O Coplien essay, most unit tests are waste. Particulary, James says:
If you want to reduce your test mass, the number one thing you should do is look at the tests that have never failed in a year and consider throwing them away. They are producing no information for you — or at least very little information. The value of the information they produce may not be worth the expense of maintaining and running the tests. This is the first set of tests to throw away — whether they are unit tests, integration tests, or system tests.
This gem lets you track tests that haven't failed for given period of time, and prompts you to "reduce test mass" by removing them.
Add this line to your application's Gemfile:
gem 'rspec-rotten'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec-rotten
Create initializer and specify path to a file that will be storing stats of your test runs, and, most importantly, time period after which specs will be considered "rotten", given they didn't change status(failed/passed/became pending):
# spec/support/rspec-rotten.rb
Rspec::Rotten::Configuration.configure do |config|
config.results_file = Rails.root.join('output.json')
config.time_to_rotten = 1.year
end
# register custom formatter with RSpec
Rspec::Rotten::Configuration.register_formatter
The line above will take over default rspec formatter, so you will have to register it again:
# spec/rails_helper.rb
RSpec.configure do |config|
...
config.add_formatter(Rspec::Rotten::Formatters::ProgressFormatter)
...
end
OR just add this line to the .rspec
(file with rspec default run options):
-f p
Run the entire suite to genreate initial spec report:
rspec spec/
NOTE: This will create the report that will reflect the status of your specs, and will be updated every time you run specs. It's recommended to check this file under source control, to share this data with your co-workers.
Now, every time you run specs, you will get an annoying message if you have "rotten" specs (it's easy to turn OFF by commenting out Formatter in step 2).
- create rake task / installer to generate initial report
- notify only about the examples currently executed (not the whole suite)
- allow user to use Formatter from CLI like
rspec --format RottenFormatter spec/
- give user a chance to only track unit/integration/acceptance specs
- Fork it ( https://github.com/[my-github-username]/rspec-rotten/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request