-
-
Notifications
You must be signed in to change notification settings - Fork 765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow config for rerun location as line number for shared or nested examples #3085
Merged
JonRowe
merged 14 commits into
rspec:main
from
kykyi:feature/issue-2119/allow-config-for-rerun-location-as-line-number-for-shared-or-nested-examples
Jul 9, 2024
+153
−1
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1ad470c
Allow configuration to allow nested or shared examples to print the f…
kykyi 6c520f3
Add a config and integration spec to assert behaviour works as expected
kykyi e1477ad
Update name of config
kykyi 9384706
Add some more specs
kykyi d5f6530
Make tests more clear
kykyi 7f9d74b
Change name of var
kykyi 2665942
Undo unintended change
kykyi dc027fb
Change config name
kykyi 1bced55
Use unindent to make the assertion strings nicer
kykyi dc64765
Update spec/integration/location_rerun_spec.rb
kykyi ae587a5
Apply suggestions from code review
kykyi 622456a
Remove empty line
kykyi 616bc56
Fix indentation
kykyi 40058a8
Use write_file_formatted
kykyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
require 'support/aruba_support' | ||
|
||
RSpec.describe 'Failed spec rerun location' do | ||
include RSpecHelpers | ||
include_context "aruba support" | ||
|
||
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_formatted "some_examples.rb", " | ||
RSpec.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 | ||
" | ||
|
||
file = cd('.') { "#{Dir.pwd}/some_examples.rb" } | ||
load file | ||
|
||
write_file_formatted "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_formatted "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 | ||
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 | ||
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 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 | ||
EOS | ||
end | ||
|
||
context "and the shared examples are defined in a separate file" do | ||
kykyi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 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 | ||
EOS | ||
end | ||
end | ||
end | ||
|
||
context "when config.force_line_number_for_spec_rerun is set to true" do | ||
before do | ||
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 | ||
|
||
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 unindent(<<-EOS) | ||
Failed examples: | ||
|
||
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 | ||
|
||
context "and the shared examples are defined in a separate file" do | ||
kykyi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 unindent(<<-EOS) | ||
Failed examples: | ||
|
||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you convert the files to use the same unident trick, should neatedn them up to as theres a stray miasligned
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the indents manually @JonRowe and have used
write_file_formatted
which callsunindent
just to use the existing util 👌https://github.com/kykyi/rspec-core/blob/39f4fdfeea8ff6c70314ba385a47f20fc370cd2c/spec/support/aruba_support.rb#L72