Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

add support for --example-matches -E that allows matching examples with regex syntax #2586

5 changes: 5 additions & 0 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as suggested

Copy link
Member

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!

Copy link
Contributor Author

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?

Copy link
Member

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!

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

" used more than once)") do |o|
(options[:full_description] ||= []) << Regexp.compile(o)
end

parser.on('-t', '--tag TAG[:VALUE]',
'Run examples with the specified tag, or exclude examples',
'by adding ~ before the tag.',
Expand Down
10 changes: 10 additions & 0 deletions spec/rspec/core/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ module RSpec::Core
end
end

%w[--example-matches -E].each do |option|
describe option do
it "does not escape the arg" do
options = Parser.parse([option, 'this (and that)\b'])
expect(options[:full_description].length).to eq(1)
expect(/this (and that)\b/).to eq(options[:full_description].first)
end
end
end

%w[--pattern -P].each do |option|
describe option do
it "sets the filename pattern" do
Expand Down