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,6 +41,7 @@ describe Guard::Watcher do
before(:all) { @guard = Guard::Guard.new }
describe "a watcher's with no action" do
context "regex pattern" do
before(:all) { @guard.watchers = [Guard::Watcher.new(/.*_spec\.rb/)] }
it "should return paths as they came" do
@ -48,6 +49,15 @@ describe Guard::Watcher do
end
end
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
describe "a watcher's action with an arity equal to 0" do
before(:all) do
@guard.watchers = [
@ -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