Skip to content

Commit

Permalink
Merge pull request #869 from rkh/curly-pattern
Browse files Browse the repository at this point in the history
add support for curly brackets with the --pattern option, fixes #868
  • Loading branch information
myronmarston committed Apr 11, 2013
2 parents d19bcca + c0632ab commit d5f5702
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions features/configuration/pattern.feature
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ Feature: pattern
Scenario: the --pattern flag makes RSpec run files matching the specified pattern and ignore the default pattern Scenario: the --pattern flag makes RSpec run files matching the specified pattern and ignore the default pattern
When I run `rspec -P "**/*_test.rb"` When I run `rspec -P "**/*_test.rb"`
Then the output should contain "1 example, 0 failures" Then the output should contain "1 example, 0 failures"

Scenario: the --pattern flag can be used to pass in multiple patterns, separated by comma
When I run `rspec -P "**/*_test.rb,**/*_spec.rb"`
Then the output should contain "3 examples, 0 failures"

Scenario: the --pattern flag accepts shell style glob unions
When I run `rspec -P "**/*_{test,spec}.rb"`
Then the output should contain "3 examples, 0 failures"
11 changes: 5 additions & 6 deletions lib/rspec/core/configuration.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -977,17 +977,16 @@ def order_groups_and_examples(&block)
private private


def get_files_to_run(paths) def get_files_to_run(paths)
patterns = pattern.split(",")
paths.map do |path| paths.map do |path|
path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
File.directory?(path) ? gather_directories(path, patterns) : extract_location(path) File.directory?(path) ? gather_directories(path) : extract_location(path)
end.flatten.sort end.flatten.sort
end end


def gather_directories(path, patterns) def gather_directories(path)
patterns.map do |pattern| stripped = "{#{pattern.gsub(/\s*,\s*/, ',')}}"
pattern =~ /^#{path}/ ? Dir[pattern.strip].sort : Dir["#{path}/{#{pattern.strip}}"].sort files = pattern.start_with?(path) ? Dir[stripped] : Dir["#{path}/#{stripped}"]
end files.sort
end end


def extract_location(path) def extract_location(path)
Expand Down
10 changes: 9 additions & 1 deletion spec/rspec/core/configuration_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def specify_consistent_ordering_of_files_to_run
%w[ a/2.rb a/1.rb a/3.rb ], %w[ a/2.rb a/1.rb a/3.rb ],
%w[ a/3.rb a/2.rb a/1.rb ] %w[ a/3.rb a/2.rb a/1.rb ]
].map do |files| ].map do |files|
Dir.should_receive(:[]).with(/^a/) { files } Dir.should_receive(:[]).with(/^\{?a/) { files }
yield yield
config.files_to_run config.files_to_run
end end
Expand Down Expand Up @@ -466,6 +466,14 @@ def specify_consistent_ordering_of_files_to_run
expect(config.files_to_run).to include("#{dir}/a_foo.rb") expect(config.files_to_run).to include("#{dir}/a_foo.rb")
expect(config.files_to_run).to include("#{dir}/a_bar.rb") expect(config.files_to_run).to include("#{dir}/a_bar.rb")
end end

it "supports curly braces glob syntax" do
config.send(setter, "**/*_{foo,bar}.rb")
dir = File.expand_path(File.dirname(__FILE__) + "/resources")
config.files_or_directories_to_run = dir
expect(config.files_to_run).to include("#{dir}/a_foo.rb")
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
end
end end
end end
end end
Expand Down

0 comments on commit d5f5702

Please sign in to comment.