Skip to content

Commit

Permalink
Improved deprecation warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy Coutable committed Dec 16, 2010
1 parent 1831bf7 commit ebe94d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/guard/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def initialize(pattern, action = nil)
# deprecation warning
if @pattern.is_a?(String) && @pattern =~ /(^(\^))|(>?(\\\.)|(\.\*))|(\(.*\))|(\[.*\])|(\$$)/
unless @@warning_printed
UI.info "DEPRECATED!\nYou have strings in your Guardfile's watch patterns that seem to represent regexps.\nGuard matchs String with == and Regexp with Regexp#match.\nYou should either use plain String (without Regexp special characters) or real Regexp.\n"
UI.info "*"*20 + "\nDEPRECATION WARNING!\n" + "*"*20
UI.info "You have strings in your Guardfile's watch patterns that seem to represent regexps.\nGuard matchs String with == and Regexp with Regexp#match.\nYou should either use plain String (without Regexp special characters) or real Regexp.\n"
@@warning_printed = true
end
UI.info "\"#{@pattern}\" has been converted to #{Regexp.new(@pattern).inspect}\n"
Expand Down
16 changes: 8 additions & 8 deletions spec/guard/watcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
describe "a watcher's action with an arity equal to 0" do
before(:all) do
@guard.watchers = [
Guard::Watcher.new(/spec_helper\.rb/, lambda { 'spec' }),
Guard::Watcher.new(/addition\.rb/, lambda { 1 + 1 }),
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('spec_helper.rb', lambda { 'spec' }),
Guard::Watcher.new('addition.rb', lambda { 1 + 1 }),
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` })
]
end

Expand Down Expand Up @@ -85,7 +85,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` })
Expand Down Expand Up @@ -125,7 +125,7 @@
describe ".match_files?" do
before(:all) do
@guard1 = Guard::Guard.new([Guard::Watcher.new(/.*_spec\.rb/)])
@guard2 = Guard::Guard.new([Guard::Watcher.new(/spec_helper\.rb/, 'spec')])
@guard2 = Guard::Guard.new([Guard::Watcher.new('spec_helper.rb', 'spec')])
@guards = [@guard1, @guard2]
end

Expand Down

0 comments on commit ebe94d2

Please sign in to comment.