From c788c00099e06d8c18519fec38e0f5a60e3bfd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=CC=81my=20Coutable?= Date: Thu, 16 Dec 2010 15:09:36 +0100 Subject: [PATCH] Fix bug that occurred when pattern was a string and no action was associated. --- lib/guard/watcher.rb | 2 +- spec/guard/watcher_spec.rb | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/guard/watcher.rb b/lib/guard/watcher.rb index df9543a..fc16b23 100644 --- a/lib/guard/watcher.rb +++ b/lib/guard/watcher.rb @@ -46,7 +46,7 @@ module Guard if @pattern.is_a?(Regexp) file.match(@pattern) else - file == @pattern + file == @pattern ? [file] : nil end end diff --git a/spec/guard/watcher_spec.rb b/spec/guard/watcher_spec.rb index 2185855..b4889c0 100644 --- a/spec/guard/watcher_spec.rb +++ b/spec/guard/watcher_spec.rb @@ -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` })