Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #614 from dblock/multiple-eees

Allow specifying multiple -e (--example) options
  • Loading branch information...
commit 22e689c86a8696c900031b7706961681848f843b 2 parents a0202ea + dc33f77
Justin Ko justinko authored
15 features/command_line/example_name_option.feature
View
@@ -8,6 +8,8 @@ Feature: --example option
This allows you to run a single uniquely named example, all examples with
similar names, all the examples in a uniquely named group, etc, etc.
+
+ You can also use the option more than once to specify multiple example matches.
Background:
Given a file named "first_spec.rb" with:
@@ -84,3 +86,16 @@ Feature: --example option
Scenario: Object#method
When I run `rspec . --example 'Array#length'`
Then the examples should all pass
+
+ Scenario: Multiple applications of example name option
+ When I run `rspec . --example 'first group' --example 'second group' --format d`
+ Then the examples should all pass
+ And the output should contain all of these:
+ |first example in first group|
+ |second example in first group|
+ |first example in second group|
+ |second example in second group|
+ And the output should not contain any of these:
+ |first example in third group|
+ |nested group first example in nested group|
+ |nested group second example in nested group|
4 lib/rspec/core/configuration.rb
View
@@ -463,9 +463,9 @@ def line_numbers=(line_numbers)
end
def full_description=(description)
- filter_run :full_description => /#{description}/
+ filter_run :full_description => Regexp.union(*Array(description).map {|d| Regexp.new(d) })
end
-
+
# @overload add_formatter(formatter)
#
# Adds a formatter to the formatters collection. `formatter` can be a
4 lib/rspec/core/drb_options.rb
View
@@ -42,7 +42,9 @@ def add_full_description(argv)
# into a regexp when received for the first time (see OptionParser).
# Hence, merely grabbing the source of this regexp will retain the
# backslashes, so we must remove them.
- argv << "--example" << @submitted_options[:full_description].source.delete('\\')
+ @submitted_options[:full_description].each do |description|
+ argv << "--example" << description.source.delete('\\')
+ end
end
end
5 lib/rspec/core/option_parser.rb
View
@@ -134,8 +134,9 @@ def parser(options)
options[:pattern] = o
end
- parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING") do |o|
- options[:full_description] = Regexp.compile(Regexp.escape(o))
+ parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING (may be',
+ ' used more than once)") do |o|
+ (options[:full_description] ||= []) << Regexp.compile(Regexp.escape(o))
end
parser.on('-l', '--line_number LINE', 'Specify line number of an example or group (may be',
8 spec/rspec/core/configuration_options_spec.rb
View
@@ -170,8 +170,8 @@
describe "--example" do
it "sets :full_description" do
- parse_options('--example','foo').should include(:full_description => /foo/)
- parse_options('-e','bar').should include(:full_description => /bar/)
+ parse_options('--example','foo').should include(:full_description => [/foo/])
+ parse_options('-e','bar').should include(:full_description => [/bar/])
end
end
@@ -321,7 +321,7 @@
options[:color].should be_true
options[:line_numbers].should eq(["37"])
options[:debug].should be_true
- options[:full_description].should eq(/foo\ bar/)
+ options[:full_description].should eq([/foo\ bar/])
options[:drb].should be_true
end
@@ -354,7 +354,7 @@
it "parses -e 'full spec description'" do
File.open("./custom.opts", "w") {|f| f << "-e 'The quick brown fox jumps over the lazy dog'"}
options = parse_options("-O", "./custom.opts")
- options[:full_description].should == /The\ quick\ brown\ fox\ jumps\ over\ the\ lazy\ dog/
+ options[:full_description].should eq([/The\ quick\ brown\ fox\ jumps\ over\ the\ lazy\ dog/])
end
end
end
5 spec/rspec/core/configuration_spec.rb
View
@@ -407,6 +407,11 @@ module RSpec::Core
config.filter.should eq({:full_description => /foo/})
end
+ it "assigns the example names as the filter on description if description is an array" do
+ config.full_description = [ "foo", "bar" ]
+ config.filter.should eq({:full_description => Regexp.union(/foo/, /bar/)})
+ end
+
describe "#default_path" do
it 'defaults to "spec"' do
config.default_path.should eq('spec')
3  spec/rspec/core/option_parser_spec.rb
View
@@ -68,7 +68,8 @@ module RSpec::Core
describe option do
it "escapes the arg" do
options = Parser.parse!([option, "this (and that)"])
- "this (and that)".should match(options[:full_description])
+ options[:full_description].length.should == 1
+ "this (and that)".should match(options[:full_description].first)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.