Show number of examples in rspec
Counting the number of specs in a test suite is difficult to do with regex due to
* Shared example groups
* Dynamic spec code (i.e. examples defined with loops)
To count the number of examples, a custom formatter can be used.
(spec/dryrunformatter.rb)
require "rspec/core/formatters/base_formatter"
class DryRunFormatter < RSpec::Core::Formatters::BaseFormatter
def start(example_count)
puts "Running #{example_count} specs"
exit(0)
end
end
Then run with rspec --require "./spec/dry_run_formatter.rb" --format DryRunFormatter spec
Written by Tommy
Related protips
1 Response
RSpec formatters have changed, here's what I used in v3.5
require "rspec/core/formatters/base_formatter"
class DryRunFormatter < RSpec::Core::Formatters::BaseFormatter
RSpec::Core::Formatters.register self, :example_started
def start(example_count)
output << "Running #{example_count.count} specs\n"
exit(0)
end
end
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rspec
Authors
Related Tags
#rspec
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#