From 589e4b83fe75fa2f832c3dba526377f43870ad47 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 9 Jul 2024 09:35:32 +0200 Subject: [PATCH] Merge pull request #3093 from makicamel/fix-non_failing_example_ids Fixed rspec --bisect to sort ids_to_run as the original order --- Changelog.md | 4 ++++ lib/rspec/core/bisect/example_minimizer.rb | 2 +- spec/integration/bisect_spec.rb | 13 +++++++++++++ .../bisect/consistently_ordered_1_specs.rb | 5 +++++ .../bisect/consistently_ordered_2_specs.rb | 9 +++++++++ .../bisect/consistently_ordered_3_specs.rb | 7 +++++++ .../bisect/consistently_ordered_4_specs.rb | 5 +++++ spec/rspec/core/resources/bisect/frieren_quote.rb | 12 ++++++++++++ spec/support/fake_bisect_runner.rb | 2 +- 9 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 spec/rspec/core/resources/bisect/consistently_ordered_1_specs.rb create mode 100644 spec/rspec/core/resources/bisect/consistently_ordered_2_specs.rb create mode 100644 spec/rspec/core/resources/bisect/consistently_ordered_3_specs.rb create mode 100644 spec/rspec/core/resources/bisect/consistently_ordered_4_specs.rb create mode 100644 spec/rspec/core/resources/bisect/frieren_quote.rb diff --git a/Changelog.md b/Changelog.md index 50bfd0d27f..eadf99eed3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,10 @@ ### Development [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.12.3...main) +Bug fixes: + +* Sort ids to run as the original order to fix `--bisect`. (Maki Kawahara, #3093) + ### 3.13.0 / 2024-02-04 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.12.3...v3.13.0) diff --git a/lib/rspec/core/bisect/example_minimizer.rb b/lib/rspec/core/bisect/example_minimizer.rb index 7ee5a4f8bb..e53ca82db8 100644 --- a/lib/rspec/core/bisect/example_minimizer.rb +++ b/lib/rspec/core/bisect/example_minimizer.rb @@ -136,7 +136,7 @@ def non_failing_example_ids end def get_expected_failures_for?(ids) - ids_to_run = ids + failed_example_ids + ids_to_run = all_example_ids & (ids + failed_example_ids) notify( :bisect_individual_run_start, :command => shell_command.repro_command_from(ids_to_run), diff --git a/spec/integration/bisect_spec.rb b/spec/integration/bisect_spec.rb index 9f79a47b2a..136bf18d7d 100644 --- a/spec/integration/bisect_spec.rb +++ b/spec/integration/bisect_spec.rb @@ -35,6 +35,19 @@ def bisect(cli_args, expected_status=nil) end end + context "when the spec ordering is consistent" do + it 'returns the minimal reproduction command' do + output = bisect(%w[ + --order defined + spec/rspec/core/resources/bisect/consistently_ordered_1_specs.rb + spec/rspec/core/resources/bisect/consistently_ordered_2_specs.rb + spec/rspec/core/resources/bisect/consistently_ordered_3_specs.rb + spec/rspec/core/resources/bisect/consistently_ordered_4_specs.rb + ]) + expect(output).to include("Bisect complete!", "rspec ./spec/rspec/core/resources/bisect/consistently_ordered_2_specs.rb[1:1] ./spec/rspec/core/resources/bisect/consistently_ordered_3_specs.rb[1:1]") + end + end + context "when the bisect command saturates the pipe" do # On OSX and Linux a file descriptor limit meant that the bisect process got stuck at a certain limit. # This test demonstrates that we can run large bisects above this limit (found to be at time of commit). diff --git a/spec/rspec/core/resources/bisect/consistently_ordered_1_specs.rb b/spec/rspec/core/resources/bisect/consistently_ordered_1_specs.rb new file mode 100644 index 0000000000..67afc9b534 --- /dev/null +++ b/spec/rspec/core/resources/bisect/consistently_ordered_1_specs.rb @@ -0,0 +1,5 @@ +# Deliberately named _specs.rb to avoid being loaded except when specified + +RSpec.describe "Order1" do + it("passes") { expect(1).to eq 1 } +end diff --git a/spec/rspec/core/resources/bisect/consistently_ordered_2_specs.rb b/spec/rspec/core/resources/bisect/consistently_ordered_2_specs.rb new file mode 100644 index 0000000000..0924c3a6e9 --- /dev/null +++ b/spec/rspec/core/resources/bisect/consistently_ordered_2_specs.rb @@ -0,0 +1,9 @@ +# Deliberately named _specs.rb to avoid being loaded except when specified + +require "rspec/core/resources/bisect/frieren_quote" + +RSpec.describe "Order2" do + before { FrierenQuote.change } + + it("passes") { expect(1).to eq 1 } +end diff --git a/spec/rspec/core/resources/bisect/consistently_ordered_3_specs.rb b/spec/rspec/core/resources/bisect/consistently_ordered_3_specs.rb new file mode 100644 index 0000000000..b9bec897cb --- /dev/null +++ b/spec/rspec/core/resources/bisect/consistently_ordered_3_specs.rb @@ -0,0 +1,7 @@ +# Deliberately named _specs.rb to avoid being loaded except when specified + +require "rspec/core/resources/bisect/frieren_quote" + +RSpec.describe "Order3" do + it("fails order-dependency") { expect(FrierenQuote.one).to eq "That is what hero Himmel would have done." } +end diff --git a/spec/rspec/core/resources/bisect/consistently_ordered_4_specs.rb b/spec/rspec/core/resources/bisect/consistently_ordered_4_specs.rb new file mode 100644 index 0000000000..7626a842a8 --- /dev/null +++ b/spec/rspec/core/resources/bisect/consistently_ordered_4_specs.rb @@ -0,0 +1,5 @@ +# Deliberately named _specs.rb to avoid being loaded except when specified + +RSpec.describe "Order4" do + it("passes") { expect(1).to eq 1 } +end diff --git a/spec/rspec/core/resources/bisect/frieren_quote.rb b/spec/rspec/core/resources/bisect/frieren_quote.rb new file mode 100644 index 0000000000..9f05b94fea --- /dev/null +++ b/spec/rspec/core/resources/bisect/frieren_quote.rb @@ -0,0 +1,12 @@ +class FrierenQuote + class << self + def one + @@one ||= "That is what hero Himmel would have done." + end + + def change + @@one = "The greatest enjoyment comes only during the pursuit of magic, you know." + end + end +end + diff --git a/spec/support/fake_bisect_runner.rb b/spec/support/fake_bisect_runner.rb index 5df2a1c37a..eff87c2f81 100644 --- a/spec/support/fake_bisect_runner.rb +++ b/spec/support/fake_bisect_runner.rb @@ -16,7 +16,7 @@ def run(ids) failures << failing_example if dependency_satisfied?(depends_upon, ids) end - RSpec::Core::Bisect::ExampleSetDescriptor.new(ids.sort, failures.sort) + RSpec::Core::Bisect::ExampleSetDescriptor.new(ids, failures.sort) end private