Last Updated: January 16, 2017
·
2.02K
· tastycode

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

1 Response
Add your 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 ·