Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make World.reset also reset example group counts #2723

Merged
merged 1 commit into from May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rspec/core/world.rb
Expand Up @@ -5,7 +5,7 @@ module Core
# Internal container for global non-configuration data.
class World
# @private
attr_reader :example_groups, :filtered_examples
attr_reader :example_groups, :filtered_examples, :example_group_counts_by_spec_file

# Used internally to determine what to do when a SIGINT is received.
attr_accessor :wants_to_quit
Expand Down Expand Up @@ -53,6 +53,7 @@ def reset
example_groups.clear
@sources_by_path.clear if defined?(@sources_by_path)
@syntax_highlighter = nil
@example_group_counts_by_spec_file = Hash.new(0)
end

# @private
Expand Down
43 changes: 43 additions & 0 deletions spec/integration/filtering_spec.rb
Expand Up @@ -66,6 +66,49 @@ def run_rerun_command_for_failing_spec
end

context "passing a line-number filter" do
it "works with different custom runners used in the same process" do
result_counter = Class.new do
RSpec::Core::Formatters.register(self, :example_passed)

attr_accessor :passed_examples

def initialize(*)
@passed_examples = 0
end

def example_passed(notification)
@passed_examples += 1
end
end

spec_file = "spec/filtering_custom_runner_spec.rb"

write_file_formatted spec_file, "
RSpec.describe 'A group' do
example('ex 1') { }
example('ex 2') { }
end
"

spec_file_path = expand_path(spec_file)

formatter = result_counter.new
RSpec.configuration.add_formatter(formatter)
opts = RSpec::Core::ConfigurationOptions.new(["#{spec_file_path}[1:1]"])
RSpec::Core::Runner.new(opts).run(StringIO.new, StringIO.new)

expect(formatter.passed_examples).to eq 1

RSpec.clear_examples

formatter = result_counter.new
RSpec.configuration.add_formatter(formatter)
opts = RSpec::Core::ConfigurationOptions.new(["#{spec_file_path}[1:2]"])
RSpec::Core::Runner.new(opts).run(StringIO.new, StringIO.new)

expect(formatter.passed_examples).to eq 1
end

it "trumps exclusions, except for :if/:unless (which are absolute exclusions)" do
write_file_formatted 'spec/a_spec.rb', "
RSpec.configure do |c|
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/core/world_spec.rb
Expand Up @@ -36,6 +36,14 @@ module RSpec::Core
RSpec.world.reset
}.to change(RSpec::ExampleGroups, :constants).to([])
end

it 'clears #example_group_counts_by_spec_file' do
RSpec.describe "group"

expect {
RSpec.world.reset
}.to change { world.example_group_counts_by_spec_file }.to be_empty
end
end

describe "#example_groups" do
Expand Down