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

Commit c6819f0

Browse files
jackscottiJack Scotti
authored andcommitted
Make ExampleGroup stop running examples when appropriate
Set `RSpec.world.wants_to_quit = true` when the required number of failed examples has been met.
1 parent 6b26f87 commit c6819f0

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

lib/rspec/core/example_group.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ def self.run_examples(reporter)
579579
instance = new(example.inspect_output)
580580
set_ivars(instance, before_context_ivars)
581581
succeeded = example.run(instance, reporter)
582-
RSpec.world.wants_to_quit = true if fail_fast? && !succeeded
582+
if !succeeded && fail_fast? && reporter.fail_fast_limit_met?
583+
RSpec.world.wants_to_quit = true
584+
end
583585
succeeded
584586
end.all?
585587
end

spec/rspec/core/example_group_spec.rb

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,13 +1342,18 @@ def extract_execution_results(group)
13421342
end
13431343

13441344
describe "#run" do
1345-
let(:reporter) { double("reporter").as_null_object }
13461345

1347-
context "with fail_fast? => true" do
1346+
context "with fail_fast and failures_required == 1" do
13481347
let(:group) do
1349-
group = RSpec.describe
1350-
allow(group).to receive(:fail_fast?) { true }
1351-
group
1348+
the_group = RSpec.describe
1349+
allow(the_group).to receive(:fail_fast?) { true }
1350+
the_group
1351+
end
1352+
let(:config) { Configuration.new }
1353+
let(:reporter) do
1354+
the_reporter = Reporter.new config
1355+
allow(the_reporter).to receive(:failures_required) { 1 }
1356+
the_reporter
13521357
end
13531358

13541359
it "does not run examples after the failed example" do
@@ -1357,7 +1362,7 @@ def extract_execution_results(group)
13571362
self.group.example('example 2') { examples_run << self; fail; }
13581363
self.group.example('example 3') { examples_run << self }
13591364

1360-
self.group.run
1365+
self.group.run(reporter)
13611366

13621367
expect(examples_run.length).to eq(2)
13631368
end
@@ -1370,6 +1375,43 @@ def extract_execution_results(group)
13701375
end
13711376
end
13721377

1378+
context "with fail_fast and failures_required = 3" do
1379+
let(:group) do
1380+
the_group = RSpec.describe
1381+
allow(the_group).to receive(:fail_fast?) { true }
1382+
the_group
1383+
end
1384+
let(:config) { Configuration.new }
1385+
1386+
let(:reporter) do
1387+
the_reporter = Reporter.new config
1388+
allow(the_reporter).to receive(:failures_required) { 3 }
1389+
the_reporter
1390+
end
1391+
1392+
it "does not run examples after 3 failed examples" do
1393+
examples_run = []
1394+
self.group.example('example 1') { examples_run << self }
1395+
self.group.example('example 2') { examples_run << self; fail; }
1396+
self.group.example('example 3') { examples_run << self; fail; }
1397+
self.group.example('example 4') { examples_run << self; fail; }
1398+
self.group.example('example 5') { examples_run << self }
1399+
1400+
self.group.run(reporter)
1401+
1402+
expect(examples_run.length).to eq(4)
1403+
end
1404+
1405+
it "sets RSpec.world.wants_to_quit flag if encountering an exception in before(:all)" do
1406+
self.group.before(:all) { raise "error in before all" }
1407+
self.group.example("equality") { expect(1).to eq(2) }
1408+
expect(self.group.run).to be_falsey
1409+
expect(RSpec.world.wants_to_quit).to be_truthy
1410+
end
1411+
end
1412+
1413+
let(:reporter) { double("reporter").as_null_object }
1414+
13731415
context "with RSpec.world.wants_to_quit=true" do
13741416
let(:group) { RSpec.describe }
13751417

0 commit comments

Comments
 (0)