-
-
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
Allow config for rerun location as line number for shared or nested examples #3085
Conversation
…ailure number line (.rb:10) instead of example id (.rb[1:1:1])
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 |
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.
This syntax is a bit gross but allows for the whole failure segment to be asserted on which is nice
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.
We use a pattern elswhere where we define a dedent helper and add a "pillar" to mark text content, I've add this as a suggestion but I did it in the browser so excuse any typos.
Any thoughts @JonRowe 🙏 |
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.
Sorry for the delay reviewing this, personally I would have preferred to see a fully configurable re-run format, but this is probably a reasonable compromise.
I do want to see the specs cleaned up slightly using our dedent pattern and I feel strongly that the config name should have force in it because we do include line numbers where possible, and its not the actual spec location if we always print a line number, it'll often be the group location in the case of shared examples.
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 |
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.
We use a pattern elswhere where we define a dedent helper and add a "pillar" to mark text content, I've add this as a suggestion but I did it in the browser so excuse any typos.
Thanks for the review @JonRowe! Should we set up cops for these leveraging
I think getting this PR in is an improvement and happy to add a more configurable solution in a follow up PR. I am not sure I fully understand what a fully configurable re-run format means, ie what are some of the options you would like to be able to be configured? |
Co-authored-by: Jon Rowe <[email protected]>
Co-authored-by: Jon Rowe <[email protected]>
We plan the unification of RuboCop config, but this is not trivial with many repos. We postponed it to after going monorepo and dropping some legacy code in RSpec 4. But it’s also not a priority, see rspec/rspec#2 |
it_behaves_like 'a failing spec' | ||
end | ||
end | ||
" |
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 calls unindent
just to use the existing util 👌
Hey @JonRowe keen to get this one merged if we can 🙏 |
Thanks |
Related to rspec/rspec#16
What is the change?
The out of the box behaviour has not changed, but a new configuration option has been added ✨
The end result is an output which is easier for humans and non-rspec computers (like
vim
orvscode
) to jump to the location of the failure 🧑💻Say you use a
shared_example
(or setup your specs inside a loop):The default output will look something like:
This PR adds the ability to instead print the failure line number:
What if the shared example is defined in another file?
As you can see in the above, the failure line number is the line where
it_behaves_like
is called from, and this is the case if theshared_example
is defined elsewhere (see new specs).Note that there is no 'ideal' situation which will match the perfect amount of information in the CLI output to the ease of re-running and subsequent debugging of specs. The current solution allows for easy re-running of tests, but is not human readable, and the solution implemented in this PR is still easily re-runnable, and a bit more readable, but at the cost of requiring a little bit more inspection in your text editor 😄