Skip to content

On the command line, filtering examples that contain parenthesis doesn't work #299

Closed
mcmire opened this Issue Feb 4, 2011 · 9 comments

3 participants

@mcmire
mcmire commented Feb 4, 2011

What I mean is if you have a spec like:

describe Foo do
  describe "bar (with baz)" do
    # ...
  end

  describe "other tests" do
    # ...
  end
end

and you want to run just the "Foo bar (with baz)" tests, if you try to say

rspec spec/my_spec.rb --example "Foo bar (with baz)"

you'll just get a message that says that no tests were run. However, if you say

rspec spec/my_spec.rb --example "Foo bar \(with baz\)"

then that works. So I think all that is happening is that the string specified is not being Regexp.escape'd. I can take a closer look at this soon, though.

@dchelimsky
RSpec member

Regexp.escape the argument to --example.

  • Closed by d0ee3df.
  • Thanks to Elliot Winkler for the suggestion.
@dchelimsky dchelimsky closed this Mar 29, 2011
@mcmire
mcmire commented Mar 29, 2011

Sweet, thanks. Sorry I never looked at it, obviously it wasn't a huge priority. Glad to know that is indeed what it was, though.

@andreastt andreastt pushed a commit that referenced this issue Apr 29, 2011
@dchelimsky dchelimsky Regexp.escape the argument to --example.
- Closes #299.
- Thanks to Elliot Winkler for the suggestion.
d0ee3df
@iromeo
iromeo commented May 19, 2011

David and Elliot,

Hi, according to "--example" option documentation - it accepts regexps patterns instead of examples names:

parser.on('-e', '--example PATTERN', "Run examples whose full descriptions match this pattern",
"(PATTERN is compiled into a Ruby regular expression)")

So there were NO bug here, because "Foo bar (with baz)" isn't a expected regexp. Looks like Elliot didn't read documentation carefully or just expected rspec 1.x behaviour which doesn't support regexp patterns for --example. Now option description and behaviour differs each from the other (after d0ee3df commit). More over all people how used regexp patterns here need to fix their scripts/runners/etc due to new Regexp.escape. So let's decide which behaviour we need here. I see three ways
1. support both regexps and full name string values for --example argument
2. correct documentation and use new behaviour
3. restore old behaviour.

As for me I always need to search only full examples or example groups names, so actually I don't use whole regexp patterns features.

@mcmire
mcmire commented May 19, 2011

Well, one could make the argument that a pattern != regexp. I don't know what David meant by "pattern", although the help text goes on to say that the pattern is compiled into a regexp, which could be taken to mean that it isn't necessarily a regexp. I agree it probably wouldn't hurt to clarify that regexp characters will be escaped, if people are used to that, but I don't really know.

In any case, I still think the argument to --example should be regexp-escaped, as I think that's what people are going to expect. I mean, when you use --example, do you think to yourself, "Well, this is a regexp, so I need to make sure to escape special characters", or do you think "I want to run examples that contain this string"? My guess is, it's the latter... at least, it is for me. And yes, it didn't come to mind, but I guess I was expecting 1.x behavior.

I'm not discounting your backward compatibility argument, though -- what if you really do want to pass a regexp to --example? Obviously, now you can't. So really the questions here are, where did the regexp feature come from and did people really use it?

@dchelimsky
RSpec member

IMO we should leave the code as/is and fix the docs. The reason is that I think the common expectation is to take the example name as/is. e.g. "when an error occurs in an after(:all) hook"

Regardless of previous behavior, I think this is the actual desire most of the time. No?

@dchelimsky dchelimsky added a commit that referenced this issue May 21, 2011
@dchelimsky dchelimsky Clarify behavior of --example command line option
- Closes #378.
- Also see #299.
54f90b3
@iromeo
iromeo commented May 24, 2011

I think this is the actual desire most of the time. No?

Yes, I agree. Sorry I was far from the internet and couldn't participate in this discussion.

@iromeo
iromeo commented May 24, 2011

Thanks!

@dchelimsky
RSpec member

FYI - I just released rspec-core-2.6.3 with the update to the command line docs.

@iromeo
iromeo commented May 24, 2011

ok, great.

@myronmarston myronmarston added a commit that referenced this issue Jul 22, 2013
@myronmarston myronmarston Add changelog entry for #299.
[ci skip]
c7df747
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.