Permalink
Browse files

Fix bug that occurred when pattern was a string and no action was ass…

…ociated.
  • Loading branch information...
1 parent d0891ef commit c788c00099e06d8c18519fec38e0f5a60e3bfd98 Rémy Coutable committed Dec 16, 2010
Showing with 16 additions and 6 deletions.
  1. +1 −1 lib/guard/watcher.rb
  2. +15 −5 spec/guard/watcher_spec.rb
View
@@ -46,7 +46,7 @@ def match_file?(file)
if @pattern.is_a?(Regexp)
file.match(@pattern)
else
- file == @pattern
+ file == @pattern ? [file] : nil
end
end
View
@@ -41,10 +41,20 @@
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 @@
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 @@
@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` })

0 comments on commit c788c00

Please sign in to comment.