-
-
Notifications
You must be signed in to change notification settings - Fork 753
add support for --example-matches -E that allows matching examples with regex syntax #2586
add support for --example-matches -E that allows matching examples with regex syntax #2586
Conversation
…th regex syntax, fixes rspec#2584 Co-authored-by: Matt Rider <[email protected]>
b575a41
to
f677950
Compare
Great start, could you add a cucumber scenario! |
lib/rspec/core/option_parser.rb
Outdated
@@ -226,6 +226,11 @@ def parser(options) | |||
(options[:full_description] ||= []) << Regexp.compile(Regexp.escape(o)) | |||
end | |||
|
|||
parser.on('-E', '--example-matches STRING', "Run examples whose full nested names match REGEX (may be", |
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.
Should probably say REGEX or PATTERN rather than string.
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.
updated as suggested
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.
You're going to need to mark the option parser block with a comment to turn off the rubocop rule, and then turn it back on at the end, sorry!
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.
@JonRowe thanks - not exactly sure what comment to add - can you be more explicit? Or is it even something you can do yourself - you can edit our PR directly in github right?
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.
Hm thats a new feature :P, I've fixed the rubocop failures but your scenario isn't working!
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.
thanks - it seems to be passing on some versions of ruby and not others - do we need to test locally on all the different versions of ruby going back to 1.8.7?
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.
It needs to work on all versions back to 1.8.7 at this point in time, I would suggest seeing what regex or command line differences there maybe in older versions?
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.
👍
sure thing - will get some cukes in in the new year |
thanks @mattwr18 for pushing up our interim work on cukes @JonRowe we're a bit stuck on trying to do a scenario where a regex is being passed through the step definition. It seems like the step definition, or the I run command is escaping the regex, although maybe we don't quite have things hooked up correctly ... we were trying: Scenario: Match only matching regex
When I run `rspec . --example-matches "first\b" --format d`
Then the examples should all pass
And the output should contain all of these:
|first|
And the output should not contain any of these:
|first example in first group|
|second example in first group|
|first example in second group|
|second example in second group|
|first example in third group|
|nested group first example in nested group|
|nested group second example in nested group| |
Yeah you probably have to escape it |
Folks, this looks really good. Thanks so much for the contribution! Can't wait to see it across the line :) |
thanks @samphippen :-) @JonRowe yeah - I think the problem is that it is being escaped and we need to prevent that ... anyway we'll be reviewing the details again this coming Friday as part of our agile development mob |
@tansaku Apologies I don't think I was clear, I believe you need to escape it yourself. So that |
thanks @JonRowe - we'll certainly try that :-) |
@JonRowe we tried escaping it precisely as you say, but that's not what we want. We need to test the unescaped regex is processed correctly by rspec, but it seems the cucumber automatically escapes regex coming through variables in step definitions. We're currently working on a way to override that default cucumber functionality in order to have the cucumber test correctly test what we want ... |
@JonRowe @samphippen - apologies for the delay - we think it's all working now - actually there wasn't a problem with escaping, our tests were just a little whacked - we've fixed them and checked that they fail when the functionality is removed - hope this is now ready to be merged! :-) |
green for us locally, but failing the CI builds :-( |
@tansaku See my comment, its a rubocop thing |
@JonRowe we've been trying to install 1.8.7 locally in order to replicate the CI failures but that seems like a mountain of errors and issues to get through to even run the test locally (installing older version of bundler etc. etc.). If you're interested here's the series of errors and fixes so far:
fixed with
next error
fixed with
next error
for which the fix is apparently https://stackoverflow.com/a/4864145/316729 but then we get:
so feels like a bit of a rabbit hole here We've analyzed the failure and it seems that it is related to our test code - the app code we changed does not introduce anything new. Ruby 1.8.7 does support the regex we are using ...
we did notice that the way the existing tests were written did make some assumptions about how the rspec output was formatted, that we saw were not necessarily followed, but difficult to check when we can't run locally and the CI is only giving us progress output ... We've tried pushing up a few changes, but they still fail - it's feeling like we are on a bit of an endless cycle of yak-shaving here :-( |
A quick investigation shows its how the command line interprets the |
thanks @JonRowe - we didn't see any difference in how the
|
@tansaku I have a working 1.8.7 installation I dare not delete to debug these sorts of things 😂 It's
I investigated by |
@JonRowe thanks so much - that's really helpful - really appreciate you taking the time to share the details BTW, we'd love to know the motivation for maintaining backwards compatibility with 1.8.7 - are there a lot of folks out there still relying on it? |
Historically the RSpec team has held the opinion that we should be one of the last people to support 1.8.7, as we are a "base" dependency, you need to test your code and we shouldn't exclude people on older Rubies. We also view dropping support for it as a breaking change in terms of semantic versioning. That said with RSpec 4 we will be dropping support for a swathe of old Rubies, especially as Rubygems and bundler have now done so. |
thanks so much for all your help @JonRowe - I think as it turns out, we can get all green by using regex other than \b - your change allowed the 1.8.7 build to pass, but then failed on some more recent rubies. Our test is effectively same using some other regex syntax (i.e. "[^_]") which does seem to pass for everything, and I think is sufficient since all we are trying to show is that at least some regex works - there's no need to exhaustively test all regex, particularly those that have variations across ruby versions. So fingers crossed, this latest will go green and can get merged in |
My pleasure, thank you for your time and your patience, merged! |
This commit was imported from rspec/rspec-core@d048c36.
fixes #2584
worked on this in @AgileVentures mob with @mattwr18 and @okothkongo1