Skip to content

Commit

Permalink
Ensure the expected example count is reported accurately.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Mar 26, 2014
1 parent a5bd210 commit 76bcb28
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/core/runner.rb
Expand Up @@ -105,7 +105,7 @@ def setup(err, out)
# or the configured failure exit code (1 by default) if specs
# failed.
def run_specs(example_groups)
@configuration.reporter.report(@world.example_count) do |reporter|
@configuration.reporter.report(@world.example_count(example_groups)) do |reporter|
begin
hook_context = SuiteHookContext.new
@configuration.hooks.run(:before, :suite, hook_context)
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/core/world.rb
Expand Up @@ -88,8 +88,8 @@ def configure_group(group)
# @api private
#
# Get count of examples to be run
def example_count
FlatMap.flat_map(example_groups) {|g| g.descendants}.
def example_count(groups=example_groups)
FlatMap.flat_map(groups) {|g| g.descendants}.
inject(0) {|sum, g| sum + g.filtered_examples.size}
end

Expand Down
37 changes: 37 additions & 0 deletions spec/rspec/core/runner_spec.rb
Expand Up @@ -202,6 +202,43 @@ def run_specs
expect(order).to eq([:start_set_1, :group_1, :start_set_2, :group_2])
end

it 'reports the expected example count accurately, even when subclasses filter example groups' do
RSpec.describe("group 1") do
example("1") { }

context "nested" do
4.times { example { } }
end
end

RSpec.describe("group 2") do
example("2") { }
example("3") { }

context "nested" do
4.times { example { } }
end
end

subclass = Class.new(Runner) do
define_method :run_specs do |example_groups|
super(example_groups.select { |g| g.description == 'group 2' })
end
end

my_formatter = instance_double(Formatters::BaseFormatter).as_null_object
config.output_stream = out
config.deprecation_stream = err
config.reporter.register_listener(my_formatter, :start)

allow(config).to receive(:load_spec_files)
subclass.new(ConfigurationOptions.new([]), config, world).run(err, out)

expect(my_formatter).to have_received(:start) do |notification|
expect(notification.count).to eq(6)
end
end

context "running files" do
include_context "spec files"

Expand Down

0 comments on commit 76bcb28

Please sign in to comment.