-
-
Notifications
You must be signed in to change notification settings - Fork 766
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
The SPEC environment variable does not support using bracketed example IDs #3062
Comments
What if we returned |
That would produce the wrong result, file list is parsing a string of filenames into an array here, its supposed to pass them through as is to the cmd but taking into account any globbing, its just a very old peice of code that was never updated to support the id syntax. We do all the work to support that in configuration, we could "simply" split on a space and then sort [sorting is done for consistency here] but that would drop globbing support, so we would probably have to map over the result and/or check for the glob to expand then sort? |
Is there a reason rspec-core/lib/rspec/core/rake_task.rb Lines 124 to 154 in f8c8880
The bug mentioned in this comment happens with |
Pattern generates a list of specs to consider the examples, SPEC was created to pass specific files within that list to rspec. Patterns don't support ids either FWIW. |
Could we partition based on the pattern? Here's a quick example partitioning by the if ENV['SPEC']
+ patterns = ENV['SPEC'].split
+ examples, rest = patterns.partition { _1.match?(/((\[\d+(:\d+)*\])|(:\d+))$/) }
+
- FileList[ENV['SPEC']].sort
+ (FileList[rest] + examples).sort
elsif String === pattern && !File.exist?(pattern)
return if [*rspec_opts].any? { |opt| opt =~ /--pattern/ }
"--pattern #{escape pattern}"
else
# Before RSpec 3.1, we used `FileList` to get the list of matched
# files, and then pass that along to the `rspec` command. Starting
# with 3.1, we prefer to pass along the pattern as-is to the `rspec`
# command, for 3 reasons:
#
# * It's *much* less verbose to pass one `--pattern` option than a
# long list of files.
# * It ensures `task.pattern` and `--pattern` have the same
# behavior.
# * It fixes a bug, where
# `task.pattern = pattern_that_matches_no_files` would run *all*
# files because it would cause no pattern or file args to get
# passed to `rspec`, which causes all files to get run.
#
# However, `FileList` is *far* more flexible than the `--pattern`
# option. Specifically, it supports individual files and directories,
# as well as arrays of files, directories and globs, as well as other
# `FileList` objects.
#
# For backwards compatibility, we have to fall back to using FileList
# if the user has passed a `pattern` option that will not work with
# `--pattern`.
#
# TODO: consider deprecating support for this and removing it in
# RSpec 4.
FileList[pattern].sort.map { |file| escape file }
end |
We could look for id based filenames and pass them directly, and pass the rest of the string to file list yes. As an aside thats not "the pattern" this file uses elsewhere, that is an accessor method containing either a custom pattern or the default which is essentially [with some extra escaping] So this statement:
Is actually incorrect, as pattern would still be set even if
In fact this is also why an id won't run any specs, nothing matches. The bug described is talking about empty pattern options being ignored by the cli and using the default instead. |
If you'd like to work on a PR to improve the pass through of ids feel free, not something I will have time for. |
Just for clarity, I was referring to the following:
Using version 3.2.2, it runs everything when an example ID is present, instead of raising. I'll look at opening a PR soon. |
Ah interesting, I guess its the same cause but slightly different faceat of the issue, file list interprets the |
Your environment
Steps to reproduce
Using the
SPEC
environment variable with brackets does not work with thespec
Rake task.Expected behavior
Only the provided example IDs are run.
Actual behavior
All examples are run, as if
SPEC
was not provided.Cause
The problem is that
Rake::FileList
recognizes the opening bracket as a glob pattern and passes it toDir.glob
which fails to find the filename because it doesn't support globbing on line number, etc. (as expected).Workaround
Manually invoke the
spec
Rake task after overridingRake::FileList::GLOB_PATTERN
to not include the[
bracket.Solution
It may be easier to not use
Rake::FileList
here, since it's actually not doing much.The text was updated successfully, but these errors were encountered: