Skip to content

Commit

Permalink
Fix spec path verification with multiple pattern
Browse files Browse the repository at this point in the history
RSpec.configuration.pattern may not satisfy a glob pattern
if multiple pattern is set (e.g. '**{,/*/**}/*_spec.rb,**/*.feature').

See also RSpec::Core::Configuration#file_glob_from.
  • Loading branch information
thedoritos committed Apr 2, 2016
1 parent 7b77566 commit 8b8bfc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/guard/rspec_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def self.spec_path?(path)
path ||= ""
path = path.sub(/:\d+\z/, "")
path = Pathname.new(path).cleanpath.to_s
File.fnmatch(pattern, path, flags)
stripped = "{#{pattern.gsub(/\s*,\s*/, ',')}}"
File.fnmatch(stripped, path, flags)
end

def dump_summary(*args)
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/guard/rspec_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,20 @@ def expected_output(spec_filename)
end
end
end

context "when RSpec 3.0 is configured to use multiple patterns" do
before do
allow(::RSpec.configuration).to receive(:pattern).
and_return("**{,/*/**}/*_spec.rb,**/*.feature")
end

it "matches a spec file with the first pattern" do
expect(described_class.spec_path?('./spec/foo_spec.rb')).to be_truthy
end

it "matches a spec file with the second pattern" do
expect(described_class.spec_path?('./spec/acceptance/bar.feature')).to be_truthy
end
end
end
end

0 comments on commit 8b8bfc1

Please sign in to comment.