Improved deprecation warning message

This commit is contained in:
Rémy Coutable 2010-12-16 09:15:14 +01:00
parent 1831bf752f
commit ebe94d213b
2 changed files with 10 additions and 9 deletions

View File

@ -9,7 +9,8 @@ module Guard
# 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"

View File

@ -51,12 +51,12 @@ describe Guard::Watcher do
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
@ -85,7 +85,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` })
@ -125,7 +125,7 @@ describe Guard::Watcher do
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