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

Commit f56aba5

Browse files
committed
Move only_failures config specs into their own file.
`configuration_spec.rb` is too huge. The API needs to remain large to support the configurability of RSpec, but we don’t need to keep all the specs in one file. I want to start breaking off different chunks into their own files. This is a first step towards that.
1 parent ab1e895 commit f56aba5

File tree

3 files changed

+128
-114
lines changed

3 files changed

+128
-114
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
module RSpec::Core
2+
RSpec.describe Configuration, "--only-failures support" do
3+
let(:config) { Configuration.new }
4+
let(:world) { World.new(config) }
5+
6+
def simulate_persisted_examples(*examples)
7+
config.example_status_persistence_file_path = "examples.txt"
8+
persister = class_double(ExampleStatusPersister).as_stubbed_const
9+
10+
allow(persister).to receive(:load_from).with("examples.txt").and_return(examples)
11+
end
12+
13+
describe "#last_run_statuses" do
14+
def last_run_statuses
15+
world.last_run_statuses
16+
end
17+
18+
context "when `example_status_persistence_file_path` is configured" do
19+
it 'gets the last run statuses from the ExampleStatusPersister' do
20+
simulate_persisted_examples(
21+
{ :example_id => "id_1", :status => "passed" },
22+
{ :example_id => "id_2", :status => "failed" }
23+
)
24+
25+
expect(last_run_statuses).to eq(
26+
'id_1' => 'passed', 'id_2' => 'failed'
27+
)
28+
end
29+
end
30+
31+
context "when `example_status_persistence_file_path` is not configured" do
32+
it 'returns a memoized value' do
33+
expect(last_run_statuses).to be(world.last_run_statuses)
34+
end
35+
36+
it 'returns a blank hash without attempting to load the persisted statuses' do
37+
config.example_status_persistence_file_path = nil
38+
39+
persister = class_double(ExampleStatusPersister).as_stubbed_const
40+
expect(persister).not_to receive(:load_from)
41+
42+
expect(last_run_statuses).to eq({})
43+
end
44+
end
45+
end
46+
47+
describe "#spec_files_with_failures" do
48+
def spec_files_with_failures
49+
world.spec_files_with_failures
50+
end
51+
52+
context "when `example_status_persistence_file_path` is configured" do
53+
it 'returns a memoized array of unique spec files that contain failed exaples' do
54+
simulate_persisted_examples(
55+
{ :example_id => "./spec_1.rb[1:1]", :status => "failed" },
56+
{ :example_id => "./spec_1.rb[1:2]", :status => "failed" },
57+
{ :example_id => "./spec_2.rb[1:2]", :status => "passed" },
58+
{ :example_id => "./spec_3.rb[1:2]", :status => "pending" },
59+
{ :example_id => "./spec_4.rb[1:2]", :status => "unknown" },
60+
{ :example_id => "./spec_5.rb[1:2]", :status => "failed" }
61+
)
62+
63+
expect(spec_files_with_failures).to(
64+
be_an(Array) &
65+
be(world.spec_files_with_failures) &
66+
contain_exactly("./spec_1.rb", "./spec_5.rb")
67+
)
68+
end
69+
end
70+
71+
context "when `example_status_persistence_file_path` is not configured" do
72+
it "returns a memoized blank array" do
73+
config.example_status_persistence_file_path = nil
74+
75+
expect(spec_files_with_failures).to(
76+
eq([]) & be(world.spec_files_with_failures)
77+
)
78+
end
79+
end
80+
end
81+
82+
describe "#files_to_run, when `only_failures` is set" do
83+
around { |ex| Dir.chdir("spec/rspec/core", &ex) }
84+
let(:default_path) { "resources" }
85+
let(:files_with_failures) { ["resources/a_spec.rb"] }
86+
let(:files_loaded_via_default_path) do
87+
configuration = Configuration.new
88+
configuration.default_path = default_path
89+
configuration.files_or_directories_to_run = []
90+
configuration.files_to_run
91+
end
92+
93+
before do
94+
expect(files_loaded_via_default_path).not_to eq(files_with_failures)
95+
config.default_path = default_path
96+
allow(RSpec.world).to receive_messages(:spec_files_with_failures => files_with_failures)
97+
config.force(:only_failures => true)
98+
end
99+
100+
context "and no explicit paths have been set" do
101+
it 'loads only the files that have failures' do
102+
config.files_or_directories_to_run = []
103+
expect(config.files_to_run).to eq(files_with_failures)
104+
end
105+
106+
it 'loads the default path if there are no files with failures' do
107+
allow(RSpec.world).to receive_messages(:spec_files_with_failures => [])
108+
config.files_or_directories_to_run = []
109+
expect(config.files_to_run).to eq(files_loaded_via_default_path)
110+
end
111+
end
112+
113+
context "and a path has been set" do
114+
it "ignores the list of files with failures, loading the configured path instead" do
115+
config.files_or_directories_to_run = ["resources/acceptance"]
116+
expect(config.files_to_run).to contain_files("resources/acceptance/foo_spec.rb")
117+
end
118+
end
119+
120+
context "and the default path has been explicitly set" do
121+
it "ignores the list of files with failures, loading the configured path instead" do
122+
config.files_or_directories_to_run = [default_path]
123+
expect(config.files_to_run).to eq(files_loaded_via_default_path)
124+
end
125+
end
126+
end
127+
end
128+
end

spec/rspec/core/configuration_spec.rb

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -488,52 +488,6 @@ def stub_expectation_adapters
488488
end
489489
end
490490

491-
context "when only_failures is set" do
492-
around { |ex| Dir.chdir("spec/rspec/core", &ex) }
493-
let(:default_path) { "resources" }
494-
let(:files_with_failures) { ["resources/a_spec.rb"] }
495-
let(:files_loaded_via_default_path) do
496-
config = Configuration.new
497-
config.default_path = default_path
498-
config.files_or_directories_to_run = []
499-
config.files_to_run
500-
end
501-
502-
before do
503-
expect(files_loaded_via_default_path).not_to eq(files_with_failures)
504-
config.default_path = default_path
505-
allow(RSpec.world).to receive_messages(:spec_files_with_failures => files_with_failures)
506-
config.force(:only_failures => true)
507-
end
508-
509-
context "and no explicit paths have been set" do
510-
it 'loads only the files that have failures' do
511-
assign_files_or_directories_to_run
512-
expect(config.files_to_run).to eq(files_with_failures)
513-
end
514-
515-
it 'loads the default path if there are no files with failures' do
516-
allow(RSpec.world).to receive_messages(:spec_files_with_failures => [])
517-
assign_files_or_directories_to_run
518-
expect(config.files_to_run).to eq(files_loaded_via_default_path)
519-
end
520-
end
521-
522-
context "and a path has been set" do
523-
it "ignores the list of files with failures, loading the configured path instead" do
524-
assign_files_or_directories_to_run "resources/acceptance"
525-
expect(config.files_to_run).to contain_files("resources/acceptance/foo_spec.rb")
526-
end
527-
end
528-
529-
context "and the default path has been explicitly set" do
530-
it "ignores the list of files with failures, loading the configured path instead" do
531-
assign_files_or_directories_to_run default_path
532-
expect(config.files_to_run).to eq(files_loaded_via_default_path)
533-
end
534-
end
535-
end
536-
537491
context "with default pattern" do
538492
it "loads files named _spec.rb" do
539493
assign_files_or_directories_to_run "spec/rspec/core/resources"

spec/rspec/core/world_spec.rb

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,74 +23,6 @@ module RSpec::Core
2323
end
2424
end
2525

26-
def simulate_persisted_examples(*examples)
27-
configuration.example_status_persistence_file_path = "examples.txt"
28-
persister = class_double(ExampleStatusPersister).as_stubbed_const
29-
30-
allow(persister).to receive(:load_from).with("examples.txt").and_return(examples)
31-
end
32-
33-
describe "#last_run_statuses" do
34-
context "when `example_status_persistence_file_path` is configured" do
35-
it 'gets the last run statuses from the ExampleStatusPersister' do
36-
simulate_persisted_examples(
37-
{ :example_id => "id_1", :status => "passed" },
38-
{ :example_id => "id_2", :status => "failed" }
39-
)
40-
41-
expect(world.last_run_statuses).to eq(
42-
'id_1' => 'passed', 'id_2' => 'failed'
43-
)
44-
end
45-
end
46-
47-
context "when `example_status_persistence_file_path` is not configured" do
48-
it 'returns a memoized value' do
49-
expect(world.last_run_statuses).to be(world.last_run_statuses)
50-
end
51-
52-
it 'returns a blank hash without attempting to load the persisted statuses' do
53-
configuration.example_status_persistence_file_path = nil
54-
55-
persister = class_double(ExampleStatusPersister).as_stubbed_const
56-
expect(persister).not_to receive(:load_from)
57-
58-
expect(world.last_run_statuses).to eq({})
59-
end
60-
end
61-
end
62-
63-
describe "#spec_files_with_failures" do
64-
context "when `example_status_persistence_file_path` is configured" do
65-
it 'returns a memoized array of unique spec files that contain failed exaples' do
66-
simulate_persisted_examples(
67-
{ :example_id => "./spec_1.rb[1:1]", :status => "failed" },
68-
{ :example_id => "./spec_1.rb[1:2]", :status => "failed" },
69-
{ :example_id => "./spec_2.rb[1:2]", :status => "passed" },
70-
{ :example_id => "./spec_3.rb[1:2]", :status => "pending" },
71-
{ :example_id => "./spec_4.rb[1:2]", :status => "unknown" },
72-
{ :example_id => "./spec_5.rb[1:2]", :status => "failed" }
73-
)
74-
75-
expect(world.spec_files_with_failures).to(
76-
be_an(Array) &
77-
be(world.spec_files_with_failures) &
78-
contain_exactly("./spec_1.rb", "./spec_5.rb")
79-
)
80-
end
81-
end
82-
83-
context "when `example_status_persistence_file_path1` is not configured" do
84-
it "returns a memoized blank array" do
85-
configuration.example_status_persistence_file_path = nil
86-
87-
expect(world.spec_files_with_failures).to(
88-
eq([]) & be(world.spec_files_with_failures)
89-
)
90-
end
91-
end
92-
end
93-
9426
describe "#all_examples" do
9527
it "contains all examples from all levels of nesting" do
9628
RSpec.describe do

0 commit comments

Comments
 (0)