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

Commit f677950

Browse files
tansakumattwr18
andcommitted
add support for --example-matches -E that allows matching examples with regex syntax, fixes #2584
Co-authored-by: Matt Rider <[email protected]>
1 parent 595747f commit f677950

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/rspec/core/option_parser.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ def parser(options)
226226
(options[:full_description] ||= []) << Regexp.compile(Regexp.escape(o))
227227
end
228228

229+
parser.on('-E', '--example-matches STRING', "Run examples whose full nested names match REGEX (may be",
230+
" used more than once)") do |o|
231+
(options[:full_description] ||= []) << Regexp.compile(o)
232+
end
233+
229234
parser.on('-t', '--tag TAG[:VALUE]',
230235
'Run examples with the specified tag, or exclude examples',
231236
'by adding ~ before the tag.',

spec/rspec/core/option_parser_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ module RSpec::Core
216216
end
217217
end
218218

219+
%w[--example-matches -E].each do |option|
220+
describe option do
221+
it "does not escape the arg" do
222+
options = Parser.parse([option, 'this (and that)\b'])
223+
expect(options[:full_description].length).to eq(1)
224+
expect(/this (and that)\b/).to eq(options[:full_description].first)
225+
end
226+
end
227+
end
228+
219229
%w[--pattern -P].each do |option|
220230
describe option do
221231
it "sets the filename pattern" do

0 commit comments

Comments
 (0)