Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 34d907e

Browse files
authored
Merge pull request #2723 from agis/gh-2721-world-reset
Make World.reset also reset example group counts
2 parents 30cfad0 + d49af13 commit 34d907e

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

lib/rspec/core/world.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Core
55
# Internal container for global non-configuration data.
66
class World
77
# @private
8-
attr_reader :example_groups, :filtered_examples
8+
attr_reader :example_groups, :filtered_examples, :example_group_counts_by_spec_file
99

1010
# Used internally to determine what to do when a SIGINT is received.
1111
attr_accessor :wants_to_quit
@@ -53,6 +53,7 @@ def reset
5353
example_groups.clear
5454
@sources_by_path.clear if defined?(@sources_by_path)
5555
@syntax_highlighter = nil
56+
@example_group_counts_by_spec_file = Hash.new(0)
5657
end
5758

5859
# @private

spec/integration/filtering_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,49 @@ def run_rerun_command_for_failing_spec
6666
end
6767

6868
context "passing a line-number filter" do
69+
it "works with different custom runners used in the same process" do
70+
result_counter = Class.new do
71+
RSpec::Core::Formatters.register(self, :example_passed)
72+
73+
attr_accessor :passed_examples
74+
75+
def initialize(*)
76+
@passed_examples = 0
77+
end
78+
79+
def example_passed(notification)
80+
@passed_examples += 1
81+
end
82+
end
83+
84+
spec_file = "spec/filtering_custom_runner_spec.rb"
85+
86+
write_file_formatted spec_file, "
87+
RSpec.describe 'A group' do
88+
example('ex 1') { }
89+
example('ex 2') { }
90+
end
91+
"
92+
93+
spec_file_path = expand_path(spec_file)
94+
95+
formatter = result_counter.new
96+
RSpec.configuration.add_formatter(formatter)
97+
opts = RSpec::Core::ConfigurationOptions.new(["#{spec_file_path}[1:1]"])
98+
RSpec::Core::Runner.new(opts).run(StringIO.new, StringIO.new)
99+
100+
expect(formatter.passed_examples).to eq 1
101+
102+
RSpec.clear_examples
103+
104+
formatter = result_counter.new
105+
RSpec.configuration.add_formatter(formatter)
106+
opts = RSpec::Core::ConfigurationOptions.new(["#{spec_file_path}[1:2]"])
107+
RSpec::Core::Runner.new(opts).run(StringIO.new, StringIO.new)
108+
109+
expect(formatter.passed_examples).to eq 1
110+
end
111+
69112
it "trumps exclusions, except for :if/:unless (which are absolute exclusions)" do
70113
write_file_formatted 'spec/a_spec.rb', "
71114
RSpec.configure do |c|

spec/rspec/core/world_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ module RSpec::Core
3636
RSpec.world.reset
3737
}.to change(RSpec::ExampleGroups, :constants).to([])
3838
end
39+
40+
it 'clears #example_group_counts_by_spec_file' do
41+
RSpec.describe "group"
42+
43+
expect {
44+
RSpec.world.reset
45+
}.to change { world.example_group_counts_by_spec_file }.to be_empty
46+
end
3947
end
4048

4149
describe "#example_groups" do

0 commit comments

Comments
 (0)