Giter Site home page Giter Site logo

Comments (9)

JonRowe avatar JonRowe commented on July 29, 2024 1

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.

from rspec-core.

pirj avatar pirj commented on July 29, 2024

What if we returned "--pattern #{escape ENV['SPEC']}" instead of the file list there?

from rspec-core.

JonRowe avatar JonRowe commented on July 29, 2024

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?

from rspec-core.

ezekg avatar ezekg commented on July 29, 2024

Is there a reason SPEC should not be treated the same as a pattern?

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

The bug mentioned in this comment happens with SPEC as well.

from rspec-core.

JonRowe avatar JonRowe commented on July 29, 2024

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.

from rspec-core.

ezekg avatar ezekg commented on July 29, 2024

Could we partition based on the pattern? Here's a quick example partitioning by the :1 and [1:2:3] suffixes.

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 

from rspec-core.

JonRowe avatar JonRowe commented on July 29, 2024

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] spec/**/*_spec.rb

So this statement:

The bug mentioned in this comment happens with SPEC as well.

Is actually incorrect, as pattern would still be set even if SPEC= something_that_doesnt_match and infact:

 SPEC=spec/rspec/core/an_non_existant_spec.rb rake spec
...
LoadError:
  cannot load such file -- /Users/jon/Code/Libs/Ruby/rspec-core/spec/rspec/core/an_non_existant_spec.rb

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.

from rspec-core.

ezekg avatar ezekg commented on July 29, 2024

Is actually incorrect, as pattern would still be set even if SPEC=something_that_doesnt_match and infact:

SPEC=spec/rspec/core/an_non_existant_spec.rb rake spec
...
LoadError:
  cannot load such file -- /Users/jon/Code/Libs/Ruby/rspec-core/spec/rspec/core/an_non_existant_spec

Just for clarity, I was referring to the following:

SPEC=spec/rspec/core/an_non_existant_spec.rb[1:2:3] rake spec

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.

from rspec-core.

JonRowe avatar JonRowe commented on July 29, 2024

Ah interesting, I guess its the same cause but slightly different faceat of the issue, file list interprets the [...] part and produces a blank list, any pattern would still be set though. I definietly think finding specs matching the line / file syntax and splitting them out of the list is the way to go then, in RSpec 4 we may just remove usage of this to aline with the CLI

from rspec-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.