Sometimes you need to know which routes are covered by your rails test suite.
Add this line to your application's Gemfile:
gem 'routes_coverage', group: :test
And then execute:
$ bundle
Or install it yourself as:
$ gem install routes_coverage
Install the gem and run your tests, then open generated report file coverage/routes.html
.
By default html report with no groupping is generated. If you need more funtionality - options in RoutesCoverage.settings
or rspec's config.routes_coverage
:
RSpec.configure do |config|
config.routes_coverage.perform_report = ENV['ROUTES_COVERAGE'] # only generate report if env var is set
config.routes_coverage.exclude_put_fallbacks = true # exclude non-hit PUT-requests where a matching PATCH exists
config.routes_coverage.include_from_controller_tests = true # include results from controller tests
config.routes_coverage.exclude_patterns << %r{PATCH /reqs} # excludes all requests matching regex
config.routes_coverage.exclude_namespaces << 'somenamespace' # excludes /somenamespace/*
config.routes_coverage.groups["Some Route group title"] = %r{^/somespace/}
config.routes_coverage.groups["Subdomain"] = { constraints: { subdomain: 'some_subdomain' }, path: '/' }
config.routes_coverage.groups["Admin"] = Regexp.union([
%r{^/admin/},
%r{^/secret_place/},
])
config.routes_coverage.format = :html # html is default, others are :full_text and :summary_text, or your custom formatter class
config.routes_coverage.minimum_coverage = 80 # %, your coverage goal
config.routes_coverage.round_precision = 0 # just round to whole percents
end
Excluded routes do not show in pending, but are shown if they're hit.
If rspec is not your choice - use
RoutesCoverage.configure do |config|
config.format = :full_text
# ...
end
or
RoutesCoverage.settings.format = :full_text
Note that coverage from include_from_controller_tests
(disabled by default) is not a true routes coverage.
Rounting is not tested in controller tests (which are deprecated in Rails 5),
but sometimes you may already have a lot of controller tests and an intent to improve green-path/business level coverage
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
To run tests against different rails versions use appraisal rake
Bug reports and pull requests are welcome on GitHub at https://github.com/Vasfed/routes_coverage.
The gem is available as open source under the terms of the MIT License.