Permalink
Browse files

restore --pattern/-P command line option (from rspec-1)

  • Loading branch information...
1 parent 83db5d5 commit 0c7a676e0274683795ebefdda2d5ee50ebdf1ccb @dchelimsky dchelimsky committed May 5, 2011
View
@@ -1,3 +1,10 @@
+### dev
+
+[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.0.rc4...master)
+
+* Enhancements
+ * Restore --pattern/-P command line option from rspec-1
+
### 2.6.0.rc4 / 2011-05-01
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.0.rc2...v2.6.0.rc4)
@@ -29,7 +29,8 @@ def self.add_setting(name, opts={})
add_setting :exclusion_filter
add_setting :inclusion_filter
add_setting :filter, :alias => :inclusion_filter
- add_setting :filename_pattern, :default => '**/*_spec.rb'
+ add_setting :pattern, :default => '**/*_spec.rb'
+ add_setting :filename_pattern, :alias => :pattern
add_setting :files_to_run
add_setting :include_or_extend_modules
add_setting :backtrace_clean_patterns
@@ -292,7 +293,7 @@ def reporter
def files_or_directories_to_run=(*files)
self.files_to_run = files.flatten.collect do |file|
if File.directory?(file)
- filename_pattern.split(",").collect do |pattern|
+ pattern.split(",").collect do |pattern|
Dir["#{file}/#{pattern.strip}"]
end
else
@@ -86,6 +86,10 @@ def parser(options)
options[:profile_examples] = o
end
+ parser.on('-P', '--pattern PATTERN', 'Load files those matching this pattern. Default is "spec/**/*_spec.rb"') do |o|
+ options[:pattern] = o
+ end
+
parser.on('-r', '--require PATH', 'Require a file') do |path|
options[:requires] ||= []
options[:requires] << path
@@ -143,16 +143,14 @@ module RSpec::Core
end
end
- context "setting the files to run" do
-
+ describe "#files_to_run" do
it "loads files not following pattern if named explicitly" do
file = "./spec/rspec/core/resources/a_bar.rb"
config.files_or_directories_to_run = file
config.files_to_run.should == [file]
end
- describe "with default --pattern" do
-
+ context "with default pattern" do
it "loads files named _spec.rb" do
dir = "./spec/rspec/core/resources"
config.files_or_directories_to_run = dir
@@ -164,80 +162,70 @@ module RSpec::Core
config.files_or_directories_to_run = file
config.files_to_run.should == [file]
end
-
end
+ end
- describe "with explicit pattern (single)" do
+ %w[pattern= filename_pattern=].each do |setter|
+ describe "##{setter}" do
+ context "with single pattern" do
+ before { config.send(setter, "**/*_foo.rb") }
+ it "loads files following pattern" do
+ file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
+ config.files_or_directories_to_run = file
+ config.files_to_run.should include(file)
+ end
- before do
- config.filename_pattern = "**/*_foo.rb"
- end
+ it "loads files in directories following pattern" do
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources")
+ config.files_or_directories_to_run = dir
+ config.files_to_run.should include("#{dir}/a_foo.rb")
+ end
- it "loads files following pattern" do
- file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
- config.files_or_directories_to_run = file
- config.files_to_run.should include(file)
+ it "does not load files in directories not following pattern" do
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources")
+ config.files_or_directories_to_run = dir
+ config.files_to_run.should_not include("#{dir}/a_bar.rb")
+ end
end
- it "loads files in directories following pattern" do
- dir = File.expand_path(File.dirname(__FILE__) + "/resources")
- config.files_or_directories_to_run = dir
- config.files_to_run.should include("#{dir}/a_foo.rb")
- end
+ context "with multiple patterns" do
+ it "supports comma separated values" do
+ config.send(setter, "**/*_foo.rb,**/*_bar.rb")
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources")
+ config.files_or_directories_to_run = dir
+ config.files_to_run.should include("#{dir}/a_foo.rb")
+ config.files_to_run.should include("#{dir}/a_bar.rb")
+ end
- it "does not load files in directories not following pattern" do
- dir = File.expand_path(File.dirname(__FILE__) + "/resources")
- config.files_or_directories_to_run = dir
- config.files_to_run.should_not include("#{dir}/a_bar.rb")
+ it "supports comma separated values with spaces" do
+ config.send(setter, "**/*_foo.rb, **/*_bar.rb")
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources")
+ config.files_or_directories_to_run = dir
+ config.files_to_run.should include("#{dir}/a_foo.rb")
+ config.files_to_run.should include("#{dir}/a_bar.rb")
+ end
end
-
end
+ end
- context "with explicit pattern (comma,separated,values)" do
-
- before do
- config.filename_pattern = "**/*_foo.rb,**/*_bar.rb"
- end
-
- it "supports comma separated values" do
- dir = File.expand_path(File.dirname(__FILE__) + "/resources")
- config.files_or_directories_to_run = dir
- config.files_to_run.should include("#{dir}/a_foo.rb")
- config.files_to_run.should include("#{dir}/a_bar.rb")
- end
-
- it "supports comma separated values with spaces" do
- dir = File.expand_path(File.dirname(__FILE__) + "/resources")
- config.files_or_directories_to_run = dir
- config.files_to_run.should include("#{dir}/a_foo.rb")
- config.files_to_run.should include("#{dir}/a_bar.rb")
- end
-
+ describe "path with line number" do
+ it "assigns the line number as the filter" do
+ config.files_or_directories_to_run = "path/to/a_spec.rb:37"
+ config.filter.should == {:line_number => 37}
end
+ end
- context "with line number" do
-
- it "assigns the line number as the filter" do
- config.files_or_directories_to_run = "path/to/a_spec.rb:37"
- config.filter.should == {:line_number => 37}
- end
-
+ context "with full_description" do
+ it "overrides :focused" do
+ config.filter_run :focused => true
+ config.full_description = "foo"
+ config.filter.should_not have_key(:focused)
end
- context "with full_description" do
- it "overrides :focused" do
- config.filter_run :focused => true
- config.full_description = "foo"
- config.filter.should_not have_key(:focused)
- end
-
- it "assigns the example name as the filter on description" do
- config.full_description = "foo"
- config.filter.should == {:full_description => /foo/}
- end
-
+ it "assigns the example name as the filter on description" do
+ config.full_description = "foo"
+ config.filter.should == {:full_description => /foo/}
end
-
end
describe "#include" do
@@ -306,7 +294,7 @@ def metadata_hash(*args)
end
- describe "run_all_when_everything_filtered?" do
+ describe "#run_all_when_everything_filtered?" do
it "defaults to false" do
config.run_all_when_everything_filtered?.should be_false
@@ -407,14 +395,14 @@ def metadata_hash(*args)
end
end
- describe 'formatter=' do
+ describe '#formatter=' do
it "delegates to add_formatter (better API for user-facing configuration)" do
config.should_receive(:add_formatter).with('these','options')
config.add_formatter('these','options')
end
end
- describe "add_formatter" do
+ describe "#add_formatter" do
it "adds to the list of formatters" do
config.add_formatter :documentation
@@ -573,7 +561,7 @@ def metadata_hash(*args)
end
end
- describe "line_number=" do
+ describe "#line_number=" do
before { config.stub(:warn) }
it "sets the line number" do
@@ -2,13 +2,10 @@
module RSpec::Core
describe OptionParser do
- before do
- RSpec.stub(:deprecate)
- end
-
let(:output_file){ mock File }
before do
+ RSpec.stub(:deprecate)
File.stub(:open).with("foo.txt",'w') { (output_file) }
end
@@ -30,17 +27,12 @@ module RSpec::Core
end
end
- describe "--format" do
- it "defines the formatter" do
- options = Parser.parse!(%w[--format doc])
- options[:formatters].first.should eq(["doc"])
- end
- end
-
- describe "-f" do
- it "defines the formatter" do
- options = Parser.parse!(%w[-f doc])
- options[:formatters].first.should eq(["doc"])
+ %w[--format -f].each do |option|
+ describe option do
+ it "defines the formatter" do
+ options = Parser.parse!([option, 'doc'])
+ options[:formatters].first.should eq(["doc"])
+ end
end
end
@@ -72,10 +64,21 @@ module RSpec::Core
end
end
- describe "--example" do
- it "escapes the arg" do
- options = Parser.parse!(["--example", "this (and that)"])
- "this (and that)".should match(options[:full_description])
+ %w[--example -e].each do |option|
+ describe option do
+ it "escapes the arg" do
+ options = Parser.parse!([option, "this (and that)"])
+ "this (and that)".should match(options[:full_description])
+ end
+ end
+ end
+
+ %w[--pattern -P].each do |option|
+ describe option do
+ it "sets the filename pattern" do
+ options = Parser.parse!([option, 'spec/**/*.spec'])
+ options[:pattern].should eq('spec/**/*.spec')
+ end
end
end

0 comments on commit 0c7a676

Please sign in to comment.