From 1ad470cb7d82cb91b40c71d91834c6f842150ac0 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sun, 12 May 2024 10:12:44 +1000 Subject: [PATCH 01/14] Allow configuration to allow nested or shared examples to print the failure number line (.rb:10) instead of example id (.rb[1:1:1]) --- lib/rspec/core/configuration.rb | 7 +++++++ lib/rspec/core/notifications.rb | 2 ++ 2 files changed, 9 insertions(+) diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index cef3e813a6..754e5ede9a 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -477,6 +477,12 @@ def pending_failure_output=(mode) @pending_failure_output = mode end + # @macro location_rerun_failed_example_uses_line_number + # Display the line number (`my_spec.rb:10`), as opposed to the example id (`my_spec.rb[1:1:1]`) + # for shared or nested examples (defaults to `false`). + # return [Boolean] + add_setting :location_rerun_failed_example_uses_line_number + # Determines which bisect runner implementation gets used to run subsets # of the suite during a bisection. Your choices are: # @@ -580,6 +586,7 @@ def initialize @world = World::Null @shared_context_metadata_behavior = :trigger_inclusion @pending_failure_output = :full + @location_rerun_failed_example_uses_line_number = false define_built_in_hooks end diff --git a/lib/rspec/core/notifications.rb b/lib/rspec/core/notifications.rb index 72768ef4e2..cb24b1e60f 100644 --- a/lib/rspec/core/notifications.rb +++ b/lib/rspec/core/notifications.rb @@ -401,6 +401,8 @@ def fully_formatted(colorizer=::RSpec::Core::Formatters::ConsoleCodes) def rerun_argument_for(example) location = example.location_rerun_argument + + return location if RSpec.configuration.location_rerun_failed_example_uses_line_number return location unless duplicate_rerun_locations.include?(location) conditionally_quote(example.id) end From 6c520f3ecf40ef053a8602140050cfcb421b3457 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sun, 12 May 2024 11:29:26 +1000 Subject: [PATCH 02/14] Add a config and integration spec to assert behaviour works as expected --- spec/integration/bisect_runners_spec.rb | 11 ------ spec/integration/location_rerun_spec.rb | 52 +++++++++++++++++++++++++ spec/rspec/core/configuration_spec.rb | 13 ++++++- 3 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 spec/integration/location_rerun_spec.rb diff --git a/spec/integration/bisect_runners_spec.rb b/spec/integration/bisect_runners_spec.rb index 591b3290dd..c97726f260 100644 --- a/spec/integration/bisect_runners_spec.rb +++ b/spec/integration/bisect_runners_spec.rb @@ -10,17 +10,6 @@ module RSpec::Core let(:shell_command) { Bisect::ShellCommand.new([]) } - def with_runner(&block) - handle_current_dir_change do - cd '.' do - options = ConfigurationOptions.new(shell_command.original_cli_args) - runner = Runner.new(options) - output = StringIO.new - runner.configure(output, output) - described_class.start(shell_command, runner, &block) - end - end - end it 'runs the specs in an isolated environment and reports the results' do RSpec.configuration.formatter = 'progress' diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb new file mode 100644 index 0000000000..f22b6b5fc1 --- /dev/null +++ b/spec/integration/location_rerun_spec.rb @@ -0,0 +1,52 @@ +require 'support/aruba_support' + +RSpec.describe 'Failed spec rerun location' do + subject(:run_spec) do + file = cd('.') { "#{Dir.pwd}/failing_spec.rb" } + load file + run_command 'failing_spec.rb' + end + + include_context "aruba support" + + before do + setup_aruba + write_file "failing_spec.rb", " + RSpec.describe do + shared_examples_for 'a failing spec' do + it 'fails' do + expect(1).to eq(2) + end + end + + context 'the first context' do + it_behaves_like 'a failing spec' + end + + context 'the second context' do + it_behaves_like 'a failing spec' + end + end + " + end + + it 'prints the example ids' do + run_spec + + expect(last_cmd_stdout).to include("/failing_spec.rb[1:1:1:1]") + expect(last_cmd_stdout).to include("/failing_spec.rb[1:2:1:1]") + end + + context "when config.location_rerun_failed_example_uses_line_number is set to true" do + before do + RSpec.configuration.location_rerun_failed_example_uses_line_number = true + end + + it 'prints the line numbers' do + run_spec + + expect(last_cmd_stdout).to include("/failing_spec.rb:10") + expect(last_cmd_stdout).to include("/failing_spec.rb:14") + end + end +end diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 165990f5aa..7969ad9365 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -1,6 +1,5 @@ require 'tmpdir' require 'rspec/support/spec/in_sub_process' - module RSpec::Core RSpec.describe Configuration do include RSpec::Support::InSubProcess @@ -2979,6 +2978,18 @@ def emulate_not_configured_expectation_framework end end + describe "#location_rerun_failed_example_uses_line_number" do + + it "defaults to false" do + expect(config.location_rerun_failed_example_uses_line_number).to eq false + end + + it "is configurable" do + config.location_rerun_failed_example_uses_line_number = true + expect(config.location_rerun_failed_example_uses_line_number).to eq true + end + end + # assigns files_or_directories_to_run and triggers post-processing # via `files_to_run`. def assign_files_or_directories_to_run(*value) From e1477adc1415bb8cb8652c4b12188e5394ebed1d Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sun, 12 May 2024 11:38:18 +1000 Subject: [PATCH 03/14] Update name of config --- lib/rspec/core/configuration.rb | 6 +++--- lib/rspec/core/notifications.rb | 2 +- spec/integration/location_rerun_spec.rb | 4 ++-- spec/rspec/core/configuration_spec.rb | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index 754e5ede9a..9aac7cf1f0 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -477,11 +477,11 @@ def pending_failure_output=(mode) @pending_failure_output = mode end - # @macro location_rerun_failed_example_uses_line_number + # @macro location_rerun_uses_line_number # Display the line number (`my_spec.rb:10`), as opposed to the example id (`my_spec.rb[1:1:1]`) # for shared or nested examples (defaults to `false`). # return [Boolean] - add_setting :location_rerun_failed_example_uses_line_number + add_setting :location_rerun_uses_line_number # Determines which bisect runner implementation gets used to run subsets # of the suite during a bisection. Your choices are: @@ -586,7 +586,7 @@ def initialize @world = World::Null @shared_context_metadata_behavior = :trigger_inclusion @pending_failure_output = :full - @location_rerun_failed_example_uses_line_number = false + @location_rerun_uses_line_number = false define_built_in_hooks end diff --git a/lib/rspec/core/notifications.rb b/lib/rspec/core/notifications.rb index cb24b1e60f..421ba5b47a 100644 --- a/lib/rspec/core/notifications.rb +++ b/lib/rspec/core/notifications.rb @@ -402,7 +402,7 @@ def fully_formatted(colorizer=::RSpec::Core::Formatters::ConsoleCodes) def rerun_argument_for(example) location = example.location_rerun_argument - return location if RSpec.configuration.location_rerun_failed_example_uses_line_number + return location if RSpec.configuration.location_rerun_uses_line_number return location unless duplicate_rerun_locations.include?(location) conditionally_quote(example.id) end diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index f22b6b5fc1..ffb0674e2f 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -37,9 +37,9 @@ expect(last_cmd_stdout).to include("/failing_spec.rb[1:2:1:1]") end - context "when config.location_rerun_failed_example_uses_line_number is set to true" do + context "when config.location_rerun_uses_line_number is set to true" do before do - RSpec.configuration.location_rerun_failed_example_uses_line_number = true + RSpec.configuration.location_rerun_uses_line_number = true end it 'prints the line numbers' do diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 7969ad9365..f988b1bb93 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -2978,15 +2978,15 @@ def emulate_not_configured_expectation_framework end end - describe "#location_rerun_failed_example_uses_line_number" do + describe "#location_rerun_uses_line_number" do it "defaults to false" do - expect(config.location_rerun_failed_example_uses_line_number).to eq false + expect(config.location_rerun_uses_line_number).to eq false end it "is configurable" do - config.location_rerun_failed_example_uses_line_number = true - expect(config.location_rerun_failed_example_uses_line_number).to eq true + config.location_rerun_uses_line_number = true + expect(config.location_rerun_uses_line_number).to eq true end end From 938470660e85401ee3ecc96a54f565dd7cb80324 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sun, 12 May 2024 12:41:02 +1000 Subject: [PATCH 04/14] Add some more specs --- spec/integration/location_rerun_spec.rb | 119 ++++++++++++++++++------ 1 file changed, 89 insertions(+), 30 deletions(-) diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index ffb0674e2f..eb4c29dbac 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -1,52 +1,111 @@ require 'support/aruba_support' RSpec.describe 'Failed spec rerun location' do - subject(:run_spec) do - file = cd('.') { "#{Dir.pwd}/failing_spec.rb" } - load file - run_command 'failing_spec.rb' - end include_context "aruba support" before do setup_aruba - write_file "failing_spec.rb", " - RSpec.describe do - shared_examples_for 'a failing spec' do - it 'fails' do - expect(1).to eq(2) - end - end - - context 'the first context' do - it_behaves_like 'a failing spec' - end - - context 'the second context' do - it_behaves_like 'a failing spec' - end + write_file "some_examples.rb", " + RSpec.shared_examples_for 'a failing spec' do + it 'fails' do + expect(1).to eq(2) + end + end + " + + file = cd('.') { "#{Dir.pwd}/some_examples.rb" } + load file + + write_file "local_shared_examples_spec.rb", " + RSpec.describe do + shared_examples_for 'a failing spec' do + it 'fails' do + expect(1).to eq(2) + end + end + + context 'the first context' do + it_behaves_like 'a failing spec' + end + + context 'the second context' do + it_behaves_like 'a failing spec' + end + end + " + + write_file "non_local_shared_examples_spec.rb", " + RSpec.describe do + context 'the first context' do + it_behaves_like 'a failing spec' + end + + context 'the second context' do + it_behaves_like 'a failing spec' end - " + end + " end - it 'prints the example ids' do - run_spec + context "when config.location_rerun_uses_line_number is set to false" do + it 'prints the example id of the failed assertion' do + run_command("#{Dir.pwd}/tmp/aruba/local_shared_examples_spec.rb") - expect(last_cmd_stdout).to include("/failing_spec.rb[1:1:1:1]") - expect(last_cmd_stdout).to include("/failing_spec.rb[1:2:1:1]") + expect(last_cmd_stdout).to include(<<-MSG +Failed examples: + +rspec './local_shared_examples_spec.rb[1:1:1:1]' # the first context behaves like a failing spec fails +rspec './local_shared_examples_spec.rb[1:2:1:1]' # the second context behaves like a failing spec fails + MSG + ) + end + context "and the shared examples are defined in a separate file" do + it 'prints the line number where the `it_behaves_like` was called in the local file' do + run_command("#{Dir.pwd}/tmp/aruba/non_local_shared_examples_spec.rb") + + expect(last_cmd_stdout).to include(<<-MSG +Failed examples: + +rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails +rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec fails + MSG + ) + end + end end context "when config.location_rerun_uses_line_number is set to true" do before do - RSpec.configuration.location_rerun_uses_line_number = true + allow(RSpec.configuration).to receive(:location_rerun_uses_line_number).and_return(true) + end + + context "when the shared examples are defined in the same file as the spec" do + + it 'prints the line number where the assertion failed in the local file' do + run_command("#{Dir.pwd}/tmp/aruba/local_shared_examples_spec.rb") + + expect(last_cmd_stdout).to include(<<-MSG +Failed examples: + +rspec ./local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails +rspec ./local_shared_examples_spec.rb:4 # the second context behaves like a failing spec fails + MSG + ) + end end + context "and the shared examples are defined in a separate file" do + it 'prints the line number where the `it_behaves_like` was called in the local file' do - it 'prints the line numbers' do - run_spec + run_command("#{Dir.pwd}/tmp/aruba/non_local_shared_examples_spec.rb") + expect(last_cmd_stdout).to include(<<-MSG +Failed examples: - expect(last_cmd_stdout).to include("/failing_spec.rb:10") - expect(last_cmd_stdout).to include("/failing_spec.rb:14") +rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails +rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec fails + MSG + ) + end end end end From d5f6530bcc730cd1def368b97e7c66a7a1b79e57 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sun, 12 May 2024 12:50:24 +1000 Subject: [PATCH 05/14] Make tests more clear --- lib/rspec/core/notifications.rb | 2 +- spec/integration/location_rerun_spec.rb | 58 +++++++++++++++++-------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/lib/rspec/core/notifications.rb b/lib/rspec/core/notifications.rb index 421ba5b47a..b75b375c2d 100644 --- a/lib/rspec/core/notifications.rb +++ b/lib/rspec/core/notifications.rb @@ -402,8 +402,8 @@ def fully_formatted(colorizer=::RSpec::Core::Formatters::ConsoleCodes) def rerun_argument_for(example) location = example.location_rerun_argument - return location if RSpec.configuration.location_rerun_uses_line_number return location unless duplicate_rerun_locations.include?(location) + return location if RSpec.configuration.location_rerun_uses_line_number conditionally_quote(example.id) end diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index eb4c29dbac..dc95791a61 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -6,23 +6,50 @@ before do setup_aruba + + # Setup some shared examples and call them in a separate file + # from where they are called to demonstrate how nested example ids work write_file "some_examples.rb", " RSpec.shared_examples_for 'a failing spec' do - it 'fails' do - expect(1).to eq(2) + it 'fails' do + expect(1).to eq(2) + end + + context 'when you reverse it' do + it 'still fails' do + expect(2).to eq(1) end - end + end + end " file = cd('.') { "#{Dir.pwd}/some_examples.rb" } load file + write_file "non_local_shared_examples_spec.rb", " + RSpec.describe do + context 'the first context' do + it_behaves_like 'a failing spec' + end + + context 'the second context' do + it_behaves_like 'a failing spec' + end + end +" + # Setup some shared examples in the same file as where they are called write_file "local_shared_examples_spec.rb", " RSpec.describe do shared_examples_for 'a failing spec' do it 'fails' do expect(1).to eq(2) end + + context 'when you reverse it' do + it 'still fails' do + expect(2).to eq(1) + end + end end context 'the first context' do @@ -35,17 +62,6 @@ end " - write_file "non_local_shared_examples_spec.rb", " - RSpec.describe do - context 'the first context' do - it_behaves_like 'a failing spec' - end - - context 'the second context' do - it_behaves_like 'a failing spec' - end - end - " end context "when config.location_rerun_uses_line_number is set to false" do @@ -56,19 +72,23 @@ Failed examples: rspec './local_shared_examples_spec.rb[1:1:1:1]' # the first context behaves like a failing spec fails +rspec './local_shared_examples_spec.rb[1:1:1:2:1]' # the first context behaves like a failing spec when you reverse it still fails rspec './local_shared_examples_spec.rb[1:2:1:1]' # the second context behaves like a failing spec fails +rspec './local_shared_examples_spec.rb[1:2:1:2:1]' # the second context behaves like a failing spec when you reverse it still fails MSG ) end context "and the shared examples are defined in a separate file" do - it 'prints the line number where the `it_behaves_like` was called in the local file' do + it 'prints the example id of the failed assertion' do run_command("#{Dir.pwd}/tmp/aruba/non_local_shared_examples_spec.rb") expect(last_cmd_stdout).to include(<<-MSG Failed examples: -rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails -rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec fails +rspec './non_local_shared_examples_spec.rb[1:1:1:1]' # the first context behaves like a failing spec fails +rspec './non_local_shared_examples_spec.rb[1:1:1:2:1]' # the first context behaves like a failing spec when you reverse it still fails +rspec './non_local_shared_examples_spec.rb[1:2:1:1]' # the second context behaves like a failing spec fails +rspec './non_local_shared_examples_spec.rb[1:2:1:2:1]' # the second context behaves like a failing spec when you reverse it still fails MSG ) end @@ -89,7 +109,9 @@ Failed examples: rspec ./local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails +rspec ./local_shared_examples_spec.rb:9 # the first context behaves like a failing spec when you reverse it still fails rspec ./local_shared_examples_spec.rb:4 # the second context behaves like a failing spec fails +rspec ./local_shared_examples_spec.rb:9 # the second context behaves like a failing spec when you reverse it still fails MSG ) end @@ -102,7 +124,9 @@ Failed examples: rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails +rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec when you reverse it still fails rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec fails +rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec when you reverse it still fails MSG ) end From 7f9d74b871b5f71f698c9e2d09a08abd3e983772 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sun, 12 May 2024 12:54:23 +1000 Subject: [PATCH 06/14] Change name of var --- lib/rspec/core/configuration.rb | 6 +++--- lib/rspec/core/notifications.rb | 2 +- spec/integration/location_rerun_spec.rb | 6 +++--- spec/rspec/core/configuration_spec.rb | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index 9aac7cf1f0..2dcec2ac02 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -477,11 +477,11 @@ def pending_failure_output=(mode) @pending_failure_output = mode end - # @macro location_rerun_uses_line_number + # @macro use_line_number_for_failed_spec_location_rerun # Display the line number (`my_spec.rb:10`), as opposed to the example id (`my_spec.rb[1:1:1]`) # for shared or nested examples (defaults to `false`). # return [Boolean] - add_setting :location_rerun_uses_line_number + add_setting :use_line_number_for_failed_spec_location_rerun # Determines which bisect runner implementation gets used to run subsets # of the suite during a bisection. Your choices are: @@ -586,7 +586,7 @@ def initialize @world = World::Null @shared_context_metadata_behavior = :trigger_inclusion @pending_failure_output = :full - @location_rerun_uses_line_number = false + @use_line_number_for_failed_spec_location_rerun = false define_built_in_hooks end diff --git a/lib/rspec/core/notifications.rb b/lib/rspec/core/notifications.rb index b75b375c2d..5f5ae6785d 100644 --- a/lib/rspec/core/notifications.rb +++ b/lib/rspec/core/notifications.rb @@ -403,7 +403,7 @@ def rerun_argument_for(example) location = example.location_rerun_argument return location unless duplicate_rerun_locations.include?(location) - return location if RSpec.configuration.location_rerun_uses_line_number + return location if RSpec.configuration.use_line_number_for_failed_spec_location_rerun conditionally_quote(example.id) end diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index dc95791a61..6f8ce86a50 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -64,7 +64,7 @@ end - context "when config.location_rerun_uses_line_number is set to false" do + context "when config.use_line_number_for_failed_spec_location_rerun is set to false" do it 'prints the example id of the failed assertion' do run_command("#{Dir.pwd}/tmp/aruba/local_shared_examples_spec.rb") @@ -95,9 +95,9 @@ end end - context "when config.location_rerun_uses_line_number is set to true" do + context "when config.use_line_number_for_failed_spec_location_rerun is set to true" do before do - allow(RSpec.configuration).to receive(:location_rerun_uses_line_number).and_return(true) + allow(RSpec.configuration).to receive(:use_line_number_for_failed_spec_location_rerun).and_return(true) end context "when the shared examples are defined in the same file as the spec" do diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index f988b1bb93..6488b2af28 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -2978,15 +2978,15 @@ def emulate_not_configured_expectation_framework end end - describe "#location_rerun_uses_line_number" do + describe "#use_line_number_for_failed_spec_location_rerun" do it "defaults to false" do - expect(config.location_rerun_uses_line_number).to eq false + expect(config.use_line_number_for_failed_spec_location_rerun).to eq false end it "is configurable" do - config.location_rerun_uses_line_number = true - expect(config.location_rerun_uses_line_number).to eq true + config.use_line_number_for_failed_spec_location_rerun = true + expect(config.use_line_number_for_failed_spec_location_rerun).to eq true end end From 2665942b9c32c89fbff8c73e9bccd1e5e40f24c1 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sun, 12 May 2024 12:56:59 +1000 Subject: [PATCH 07/14] Undo unintended change --- spec/integration/bisect_runners_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/integration/bisect_runners_spec.rb b/spec/integration/bisect_runners_spec.rb index c97726f260..591b3290dd 100644 --- a/spec/integration/bisect_runners_spec.rb +++ b/spec/integration/bisect_runners_spec.rb @@ -10,6 +10,17 @@ module RSpec::Core let(:shell_command) { Bisect::ShellCommand.new([]) } + def with_runner(&block) + handle_current_dir_change do + cd '.' do + options = ConfigurationOptions.new(shell_command.original_cli_args) + runner = Runner.new(options) + output = StringIO.new + runner.configure(output, output) + described_class.start(shell_command, runner, &block) + end + end + end it 'runs the specs in an isolated environment and reports the results' do RSpec.configuration.formatter = 'progress' From dc027fb7a336529a2996dfab77ed73ad41b23bc3 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Fri, 14 Jun 2024 15:20:01 +1000 Subject: [PATCH 08/14] Change config name --- lib/rspec/core/configuration.rb | 6 +++--- lib/rspec/core/notifications.rb | 2 +- spec/integration/location_rerun_spec.rb | 6 +++--- spec/rspec/core/configuration_spec.rb | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/rspec/core/configuration.rb b/lib/rspec/core/configuration.rb index 2dcec2ac02..f8430e79f9 100644 --- a/lib/rspec/core/configuration.rb +++ b/lib/rspec/core/configuration.rb @@ -477,11 +477,11 @@ def pending_failure_output=(mode) @pending_failure_output = mode end - # @macro use_line_number_for_failed_spec_location_rerun + # @macro force_line_number_for_spec_rerun # Display the line number (`my_spec.rb:10`), as opposed to the example id (`my_spec.rb[1:1:1]`) # for shared or nested examples (defaults to `false`). # return [Boolean] - add_setting :use_line_number_for_failed_spec_location_rerun + add_setting :force_line_number_for_spec_rerun # Determines which bisect runner implementation gets used to run subsets # of the suite during a bisection. Your choices are: @@ -586,7 +586,7 @@ def initialize @world = World::Null @shared_context_metadata_behavior = :trigger_inclusion @pending_failure_output = :full - @use_line_number_for_failed_spec_location_rerun = false + @force_line_number_for_spec_rerun = false define_built_in_hooks end diff --git a/lib/rspec/core/notifications.rb b/lib/rspec/core/notifications.rb index 5f5ae6785d..0342d4bf97 100644 --- a/lib/rspec/core/notifications.rb +++ b/lib/rspec/core/notifications.rb @@ -403,7 +403,7 @@ def rerun_argument_for(example) location = example.location_rerun_argument return location unless duplicate_rerun_locations.include?(location) - return location if RSpec.configuration.use_line_number_for_failed_spec_location_rerun + return location if RSpec.configuration.force_line_number_for_spec_rerun conditionally_quote(example.id) end diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index 6f8ce86a50..1e49a287cc 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -64,7 +64,7 @@ end - context "when config.use_line_number_for_failed_spec_location_rerun is set to false" do + context "when config.force_line_number_for_spec_rerun is set to false" do it 'prints the example id of the failed assertion' do run_command("#{Dir.pwd}/tmp/aruba/local_shared_examples_spec.rb") @@ -95,9 +95,9 @@ end end - context "when config.use_line_number_for_failed_spec_location_rerun is set to true" do + context "when config.force_line_number_for_spec_rerun is set to true" do before do - allow(RSpec.configuration).to receive(:use_line_number_for_failed_spec_location_rerun).and_return(true) + allow(RSpec.configuration).to receive(:force_line_number_for_spec_rerun).and_return(true) end context "when the shared examples are defined in the same file as the spec" do diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 6488b2af28..9435acc5d8 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -2978,15 +2978,15 @@ def emulate_not_configured_expectation_framework end end - describe "#use_line_number_for_failed_spec_location_rerun" do + describe "#force_line_number_for_spec_rerun" do it "defaults to false" do - expect(config.use_line_number_for_failed_spec_location_rerun).to eq false + expect(config.force_line_number_for_spec_rerun).to eq false end it "is configurable" do - config.use_line_number_for_failed_spec_location_rerun = true - expect(config.use_line_number_for_failed_spec_location_rerun).to eq true + config.force_line_number_for_spec_rerun = true + expect(config.force_line_number_for_spec_rerun).to eq true end end From 1bced55529c562befa28966f7001c2e831b978d1 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Fri, 14 Jun 2024 15:51:14 +1000 Subject: [PATCH 09/14] Use unindent to make the assertion strings nicer --- spec/integration/location_rerun_spec.rb | 66 ++++++++++++------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index 1e49a287cc..69364700aa 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -1,6 +1,7 @@ require 'support/aruba_support' RSpec.describe 'Failed spec rerun location' do + include RSpecHelpers include_context "aruba support" @@ -68,29 +69,27 @@ it 'prints the example id of the failed assertion' do run_command("#{Dir.pwd}/tmp/aruba/local_shared_examples_spec.rb") - expect(last_cmd_stdout).to include(<<-MSG -Failed examples: + expect(last_cmd_stdout).to include unindent(<<-EOS) + Failed examples: -rspec './local_shared_examples_spec.rb[1:1:1:1]' # the first context behaves like a failing spec fails -rspec './local_shared_examples_spec.rb[1:1:1:2:1]' # the first context behaves like a failing spec when you reverse it still fails -rspec './local_shared_examples_spec.rb[1:2:1:1]' # the second context behaves like a failing spec fails -rspec './local_shared_examples_spec.rb[1:2:1:2:1]' # the second context behaves like a failing spec when you reverse it still fails - MSG - ) + rspec './local_shared_examples_spec.rb[1:1:1:1]' # the first context behaves like a failing spec fails + rspec './local_shared_examples_spec.rb[1:1:1:2:1]' # the first context behaves like a failing spec when you reverse it still fails + rspec './local_shared_examples_spec.rb[1:2:1:1]' # the second context behaves like a failing spec fails + rspec './local_shared_examples_spec.rb[1:2:1:2:1]' # the second context behaves like a failing spec when you reverse it still fails + EOS end context "and the shared examples are defined in a separate file" do it 'prints the example id of the failed assertion' do run_command("#{Dir.pwd}/tmp/aruba/non_local_shared_examples_spec.rb") - expect(last_cmd_stdout).to include(<<-MSG -Failed examples: + expect(last_cmd_stdout).to include unindent(<<-EOS) + Failed examples: -rspec './non_local_shared_examples_spec.rb[1:1:1:1]' # the first context behaves like a failing spec fails -rspec './non_local_shared_examples_spec.rb[1:1:1:2:1]' # the first context behaves like a failing spec when you reverse it still fails -rspec './non_local_shared_examples_spec.rb[1:2:1:1]' # the second context behaves like a failing spec fails -rspec './non_local_shared_examples_spec.rb[1:2:1:2:1]' # the second context behaves like a failing spec when you reverse it still fails - MSG - ) + rspec './non_local_shared_examples_spec.rb[1:1:1:1]' # the first context behaves like a failing spec fails + rspec './non_local_shared_examples_spec.rb[1:1:1:2:1]' # the first context behaves like a failing spec when you reverse it still fails + rspec './non_local_shared_examples_spec.rb[1:2:1:1]' # the second context behaves like a failing spec fails + rspec './non_local_shared_examples_spec.rb[1:2:1:2:1]' # the second context behaves like a failing spec when you reverse it still fails + EOS end end end @@ -105,30 +104,29 @@ it 'prints the line number where the assertion failed in the local file' do run_command("#{Dir.pwd}/tmp/aruba/local_shared_examples_spec.rb") - expect(last_cmd_stdout).to include(<<-MSG -Failed examples: + expect(last_cmd_stdout).to include unindent(<<-EOS) + Failed examples: -rspec ./local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails -rspec ./local_shared_examples_spec.rb:9 # the first context behaves like a failing spec when you reverse it still fails -rspec ./local_shared_examples_spec.rb:4 # the second context behaves like a failing spec fails -rspec ./local_shared_examples_spec.rb:9 # the second context behaves like a failing spec when you reverse it still fails - MSG - ) + rspec ./local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails + rspec ./local_shared_examples_spec.rb:9 # the first context behaves like a failing spec when you reverse it still fails + rspec ./local_shared_examples_spec.rb:4 # the second context behaves like a failing spec fails + rspec ./local_shared_examples_spec.rb:9 # the second context behaves like a failing spec when you reverse it still fails + EOS end end context "and the shared examples are defined in a separate file" do it 'prints the line number where the `it_behaves_like` was called in the local file' do - run_command("#{Dir.pwd}/tmp/aruba/non_local_shared_examples_spec.rb") - expect(last_cmd_stdout).to include(<<-MSG -Failed examples: - -rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails -rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec when you reverse it still fails -rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec fails -rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec when you reverse it still fails - MSG - ) + + expect(last_cmd_stdout).to include unindent(<<-EOS) + Failed examples: + + rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails + rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec when you reverse it still fails + rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec fails + rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec when you reverse it still fails + EOS + end end end From dc6476531ddecd8aed4401069e5149be2e76a1b5 Mon Sep 17 00:00:00 2001 From: Baden Ashford <61734478+kykyi@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:01:00 +1000 Subject: [PATCH 10/14] Update spec/integration/location_rerun_spec.rb Co-authored-by: Jon Rowe --- spec/integration/location_rerun_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index 69364700aa..fb9b51efa7 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -2,7 +2,6 @@ RSpec.describe 'Failed spec rerun location' do include RSpecHelpers - include_context "aruba support" before do From ae587a590730773dc1a6310cc52dca2d9d2d3aa1 Mon Sep 17 00:00:00 2001 From: Baden Ashford <61734478+kykyi@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:01:20 +1000 Subject: [PATCH 11/14] Apply suggestions from code review Co-authored-by: Jon Rowe --- spec/integration/location_rerun_spec.rb | 2 ++ spec/rspec/core/configuration_spec.rb | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index fb9b51efa7..ea363e6aa9 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -77,6 +77,7 @@ rspec './local_shared_examples_spec.rb[1:2:1:2:1]' # the second context behaves like a failing spec when you reverse it still fails EOS end + context "and the shared examples are defined in a separate file" do it 'prints the example id of the failed assertion' do run_command("#{Dir.pwd}/tmp/aruba/non_local_shared_examples_spec.rb") @@ -113,6 +114,7 @@ EOS end end + context "and the shared examples are defined in a separate file" do it 'prints the line number where the `it_behaves_like` was called in the local file' do run_command("#{Dir.pwd}/tmp/aruba/non_local_shared_examples_spec.rb") diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 9435acc5d8..19512f1666 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -2979,7 +2979,6 @@ def emulate_not_configured_expectation_framework end describe "#force_line_number_for_spec_rerun" do - it "defaults to false" do expect(config.force_line_number_for_spec_rerun).to eq false end From 622456aa321b50a32dd859d20092ebe42bf10377 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Fri, 14 Jun 2024 21:34:52 +1000 Subject: [PATCH 12/14] Remove empty line --- spec/integration/location_rerun_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index ea363e6aa9..a8db870af6 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -127,7 +127,6 @@ rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec fails rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec when you reverse it still fails EOS - end end end From 616bc563e77d9a1f4bf99b3c02e731c09678cc37 Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sat, 15 Jun 2024 08:01:27 +1000 Subject: [PATCH 13/14] Fix indentation --- spec/integration/location_rerun_spec.rb | 46 ++++++++++++------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index a8db870af6..dc4406b3a4 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -12,7 +12,7 @@ write_file "some_examples.rb", " RSpec.shared_examples_for 'a failing spec' do it 'fails' do - expect(1).to eq(2) + expect(1).to eq(2) end context 'when you reverse it' do @@ -20,48 +20,48 @@ expect(2).to eq(1) end end - end + end " file = cd('.') { "#{Dir.pwd}/some_examples.rb" } load file write_file "non_local_shared_examples_spec.rb", " - RSpec.describe do + RSpec.describe do context 'the first context' do - it_behaves_like 'a failing spec' + it_behaves_like 'a failing spec' end context 'the second context' do - it_behaves_like 'a failing spec' + it_behaves_like 'a failing spec' end - end -" + end + " + # Setup some shared examples in the same file as where they are called write_file "local_shared_examples_spec.rb", " RSpec.describe do - shared_examples_for 'a failing spec' do - it 'fails' do - expect(1).to eq(2) - end - - context 'when you reverse it' do - it 'still fails' do - expect(2).to eq(1) - end - end + shared_examples_for 'a failing spec' do + it 'fails' do + expect(1).to eq(2) end - context 'the first context' do - it_behaves_like 'a failing spec' + context 'when you reverse it' do + it 'still fails' do + expect(2).to eq(1) + end end + end - context 'the second context' do - it_behaves_like 'a failing spec' - end + context 'the first context' do + it_behaves_like 'a failing spec' + end + + context 'the second context' do + it_behaves_like 'a failing spec' + end end " - end context "when config.force_line_number_for_spec_rerun is set to false" do From 40058a8dd575ee67f19f9ed942fb4cec6e80518e Mon Sep 17 00:00:00 2001 From: Baden Ashford Date: Sat, 15 Jun 2024 08:19:19 +1000 Subject: [PATCH 14/14] Use write_file_formatted --- spec/integration/location_rerun_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/integration/location_rerun_spec.rb b/spec/integration/location_rerun_spec.rb index dc4406b3a4..aebd197653 100644 --- a/spec/integration/location_rerun_spec.rb +++ b/spec/integration/location_rerun_spec.rb @@ -9,7 +9,7 @@ # Setup some shared examples and call them in a separate file # from where they are called to demonstrate how nested example ids work - write_file "some_examples.rb", " + write_file_formatted "some_examples.rb", " RSpec.shared_examples_for 'a failing spec' do it 'fails' do expect(1).to eq(2) @@ -26,7 +26,7 @@ file = cd('.') { "#{Dir.pwd}/some_examples.rb" } load file - write_file "non_local_shared_examples_spec.rb", " + write_file_formatted "non_local_shared_examples_spec.rb", " RSpec.describe do context 'the first context' do it_behaves_like 'a failing spec' @@ -39,7 +39,7 @@ " # Setup some shared examples in the same file as where they are called - write_file "local_shared_examples_spec.rb", " + write_file_formatted "local_shared_examples_spec.rb", " RSpec.describe do shared_examples_for 'a failing spec' do it 'fails' do @@ -107,10 +107,10 @@ expect(last_cmd_stdout).to include unindent(<<-EOS) Failed examples: - rspec ./local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails - rspec ./local_shared_examples_spec.rb:9 # the first context behaves like a failing spec when you reverse it still fails - rspec ./local_shared_examples_spec.rb:4 # the second context behaves like a failing spec fails - rspec ./local_shared_examples_spec.rb:9 # the second context behaves like a failing spec when you reverse it still fails + rspec ./local_shared_examples_spec.rb:3 # the first context behaves like a failing spec fails + rspec ./local_shared_examples_spec.rb:8 # the first context behaves like a failing spec when you reverse it still fails + rspec ./local_shared_examples_spec.rb:3 # the second context behaves like a failing spec fails + rspec ./local_shared_examples_spec.rb:8 # the second context behaves like a failing spec when you reverse it still fails EOS end end @@ -122,10 +122,10 @@ expect(last_cmd_stdout).to include unindent(<<-EOS) Failed examples: - rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec fails - rspec ./non_local_shared_examples_spec.rb:4 # the first context behaves like a failing spec when you reverse it still fails - rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec fails - rspec ./non_local_shared_examples_spec.rb:8 # the second context behaves like a failing spec when you reverse it still fails + rspec ./non_local_shared_examples_spec.rb:3 # the first context behaves like a failing spec fails + rspec ./non_local_shared_examples_spec.rb:3 # the first context behaves like a failing spec when you reverse it still fails + rspec ./non_local_shared_examples_spec.rb:7 # the second context behaves like a failing spec fails + rspec ./non_local_shared_examples_spec.rb:7 # the second context behaves like a failing spec when you reverse it still fails EOS end end