8000 Allow specifying multiple -e (--example) options by dblock · Pull Request #614 · rspec/rspec-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Allow specifying multiple -e (--example) options #614

Merged
merged 2 commits into from
May 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions features/command_line/example_name_option.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 changes: 2 additions & 2 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,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
Expand Down
4 changes: 3 additions & 1 deletion lib/rspec/core/drb_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions spec/rspec/core/configuration_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/])
< 8000 span class='blob-code-inner blob-code-marker ' data-code-marker="+"> parse_options('-e','bar').should include(:full_description => [/bar/])
end
end

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,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')
Expand Down
3 changes: 2 additions & 1 deletion spec/rspec/core/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
0