Skip to content

Example ids

gitlab-qa-bot requested to merge example-ids into master

Created by: myronmarston

  • This introduces a new metadata key :rerun_file_path. This is usually the same as :file_path but can be different for situations such as an abstract example defined in a shared example group. In that situation :file_path would be file the shared example group is defined in (e.g. spec/support/model_shared_examples.rb), whereas :rerun_file_path would be the file would be something like spec/models/my_model_spec.rb -- a particular spec file that includes the shared example group. The :rerun_file_path is the file arg you would have to pass to rspec to cause the example to be re-run.
  • I wound up with a slightly different format for example ids than what was discussed in #1767 (closed) (e.g. ./spec/rspec/core/example_spec.rb[1:14]). You can also specify multiple examples or groups: ./spec/rspec/core/example_spec.rb[1:14,1:15]. I thought the brackets make a nice syntax for separating the id part from the file part, and it makes it clear that you are passing an example id, whereas in the syntax suggested in #1767 (closed), it's harder to differentiate between an id filter and a location filter -- file_name:1 would be ambiguous about whether it's a line number or id filter. This allows us to support passing ids simply as the main args to rspec, e.g. rspec ./spec/rspec/core/example_spec.rb[1:1] ./spec/rspec/core/example_group_spec.rb[1:1], which I think is better than a specific --ids flag. One downside to this syntax is that zsh makes you wrap it in quotes due to the use of [...]. Bash doesn't, though. I'm not sure about Windows, but it's the syntax Rake uses for task arguments so I figured it's already been vetted and proved out by rake and I have to assume rake works fine on windows.
  • The rerun command printed for each failed example will now use the example id if the location would match multiple examples, so that the rerun command is always guaranteed to match only the specific example it is intended for. (This is commonly needed for failed examples from shared example groups). One issue with this change: if you run zsh (as I do), you can't simply copy and paste the rerun command anymore in these situations, since zsh forces you to escape the [] characters. It'd be nice to do something about that but I'm not sure what.

TODOs:

  • Ensure rerun command can be copied/pasted in zsh
  • Add changelog entries

Merge request reports