Skip to content

Commit

Permalink
add support for curly brackets with the --pattern option, fixes rspec…
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Apr 10, 2013
1 parent d19bcca commit 4a0f1f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions features/configuration/pattern.feature
Original file line number 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
When I run `rspec -P "**/*_test.rb"`
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 Diff line number Diff line change
Expand Up @@ -977,17 +977,16 @@ def order_groups_and_examples(&block)
private

def get_files_to_run(paths)
patterns = pattern.split(",")
paths.map do |path|
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

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

def extract_location(path)
Expand Down

0 comments on commit 4a0f1f1

Please sign in to comment.