lib/page_magic/watchers.rb in page_magic-1.2.1 vs lib/page_magic/watchers.rb in page_magic-1.2.3
- old
+ new
@@ -1,11 +1,11 @@
require 'page_magic/watcher'
module PageMagic
# module Watchers - contains methods for adding watchers and checking them
module Watchers
- ELEMENT_MISSING_MSG = 'Unable to defined watcher: Element or method with the name %s can not be found'
+ ELEMENT_MISSING_MSG = 'Unable to defined watcher: Element or method with the name %s can not be found'.freeze
# @param [Symbol] name - the name of the watcher
# @return [Boolean] true if a change is detected
def changed?(name)
watched_element = watcher(name)
@@ -21,10 +21,10 @@
# @example
# watch(:something) do
# # more complicated code to get value
# end
def watch(name, method = nil, &block)
- fail ElementMissingException, (ELEMENT_MISSING_MSG % name) unless block || respond_to?(name)
+ raise ElementMissingException, (ELEMENT_MISSING_MSG % name) unless block || respond_to?(name)
watched_element = block ? Watcher.new(name, &block) : Watcher.new(name, method)
watchers.delete_if { |w| w.name == name }
watchers << watched_element.check(self)
end