lib/howitzer/web/page_validator.rb in howitzer-2.0.1 vs lib/howitzer/web/page_validator.rb in howitzer-2.0.2

- old
+ new

@@ -19,11 +19,10 @@ # Checks if any validations are defined for the page # @raise [Howitzer::NoValidationError] if no one validation is defined for the page def check_validations_are_defined! return if self.class.validations.present? - raise Howitzer::NoValidationError, "No any page validation was found for '#{self.class.name}' page" end # This module holds page validation class methods module ClassMethods @@ -32,10 +31,11 @@ # @param value [Symbol, String, Regexp] # For :url and :title validation types must be <b>Regexp</b> # For :element_presence must be one of element names described for page # @param additional_value [Object, nil] any value required to pass for a labmda selector # @raise [Howitzer::UnknownValidationError] if unknown validation type + # @raise [Howitzer::UndefinedElementError] if :element_presence validations refers to undefined element name # @example # class ArticleListPage < Howitzer::Web::Page # validate :title, /\ADemo web application - Listing Articles\z/ # end # @example @@ -79,9 +79,13 @@ private def validate_element(element_name, value = nil) validations[:element_presence] = lambda do |web_page, sync| + if element_name.present? && !private_method_defined?("#{element_name}_element") + raise(Howitzer::UndefinedElementError, ':element_presence validation refers to ' \ + "undefined '#{element_name}' element on '#{name}' page.") + end if sync web_page.instance.public_send(*["has_#{element_name}_element?", value].compact) else !web_page.instance.public_send(*["has_no_#{element_name}_element?", value].compact) end