Fix bug that occurred when pattern was a string and no action was associated.

This commit is contained in:
Rémy Coutable 2010-12-16 15:09:36 +01:00
parent d0891efdc0
commit c788c00099
2 changed files with 16 additions and 6 deletions

View File

@ -46,7 +46,7 @@ module Guard
if @pattern.is_a?(Regexp)
file.match(@pattern)
else
file == @pattern
file == @pattern ? [file] : nil
end
end

View File

@ -41,10 +41,20 @@ describe Guard::Watcher do
before(:all) { @guard = Guard::Guard.new }
describe "a watcher's with no action" do
before(:all) { @guard.watchers = [Guard::Watcher.new(/.*_spec\.rb/)] }
context "regex pattern" do
before(:all) { @guard.watchers = [Guard::Watcher.new(/.*_spec\.rb/)] }
it "should return paths as they came" do
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb']).should == ['guard_rocks_spec.rb']
end
end
it "should return paths as they came" do
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb']).should == ['guard_rocks_spec.rb']
context "string pattern" do
before(:all) { @guard.watchers = [Guard::Watcher.new('guard_rocks_spec.rb')] }
it "should return paths as they came" do
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb']).should == ['guard_rocks_spec.rb']
end
end
end
@ -56,7 +66,7 @@ describe Guard::Watcher do
Guard::Watcher.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
Guard::Watcher.new('array.rb', lambda { ['foo', 'bar'] }),
Guard::Watcher.new('blank.rb', lambda { '' }),
Guard::Watcher.new('uptime.rb', lambda { `uptime > /dev/null` })
Guard::Watcher.new(/^uptime\.rb/, lambda { `uptime > /dev/null` })
]
end
@ -85,7 +95,7 @@ describe Guard::Watcher do
@guard.watchers = [
Guard::Watcher.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
Guard::Watcher.new(/addition(.*)\.rb/, lambda { |m| 1 + 1 }),
Guard::Watcher.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
Guard::Watcher.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
Guard::Watcher.new(/array(.*)\.rb/, lambda { |m| ['foo', 'bar'] }),
Guard::Watcher.new(/blank(.*)\.rb/, lambda { |m| '' }),
Guard::Watcher.new(/uptime(.*)\.rb/, lambda { |m| `uptime > /dev/null` })