Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for curly brackets with the --pattern option, fixes #868 #869

Merged
merged 1 commit into from Apr 11, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions features/configuration/pattern.feature
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
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.gsub(/\s*,\s*/, ',')}}"
files = pattern.start_with?(path) ? Dir[stripped] : Dir["#{path}/#{stripped}"]
files.sort
end

def extract_location(path)
Expand Down
10 changes: 9 additions & 1 deletion spec/rspec/core/configuration_spec.rb
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/3.rb a/2.rb a/1.rb ]
].map do |files|
Dir.should_receive(:[]).with(/^a/) { files }
Dir.should_receive(:[]).with(/^\{?a/) { files }
yield
config.files_to_run
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_bar.rb")
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
Expand Down