Class: PrismChecker::CheckDispatcher
- Inherits:
-
Object
- Object
- PrismChecker::CheckDispatcher
- Defined in:
- lib/prism_checker/check_dispatcher.rb
Constant Summary collapse
- COMMON_ELEMENT_CHECKERS =
{ string: [ItemChecker::Element::Visible, ItemChecker::Element::String], empty: [ItemChecker::Element::Empty], regexp: [ItemChecker::Element::Visible, ItemChecker::Element::Regexp], hash: [ItemChecker::Element::Visible], visible: [ItemChecker::Element::Visible], invisible: [ItemChecker::Element::Invisible] }.freeze
- COMMON_ELEMENTS_CHECKERS =
{ string: [ItemChecker::Elements::String], empty: [ItemChecker::Elements::Empty], regexp: [ItemChecker::Elements::Regexp], array: [ItemChecker::Elements::Array], number: [ItemChecker::Elements::Number] }.freeze
- COMMON_INPUT_CHECKERS =
{ string: [ItemChecker::Element::Visible, ItemChecker::Input::String], empty: [ItemChecker::Element::Visible, ItemChecker::Input::Empty], regexp: [ItemChecker::Element::Visible, ItemChecker::Input::Regexp], hash: [ItemChecker::Element::Visible], visible: [ItemChecker::Element::Visible], invisible: [ItemChecker::Element::Invisible] }.freeze
- CHECK_MAP =
{ page: { string: [ItemChecker::Page::Loaded, ItemChecker::Page::String], regexp: [ItemChecker::Page::Loaded, ItemChecker::Page::Regexp], hash: [ItemChecker::Page::Loaded] }, section: COMMON_ELEMENT_CHECKERS, element: COMMON_ELEMENT_CHECKERS, sections: COMMON_ELEMENTS_CHECKERS, elements: COMMON_ELEMENTS_CHECKERS, image: { string: [ItemChecker::Element::Visible, ItemChecker::Image::String], regexp: [ItemChecker::Element::Visible, ItemChecker::Image::Regexp], hash: [ItemChecker::Element::Visible], visible: [ItemChecker::Element::Visible], invisible: [ItemChecker::Element::Invisible] }, input: COMMON_INPUT_CHECKERS, textarea: COMMON_INPUT_CHECKERS, select: COMMON_INPUT_CHECKERS, radio: { string: [ItemChecker::Element::Visible, ItemChecker::Input::String], regexp: [ItemChecker::Element::Visible, ItemChecker::Input::Regexp], hash: [ItemChecker::Element::Visible], visible: [ItemChecker::Element::Visible], invisible: [ItemChecker::Element::Invisible], boolean: [ItemChecker::Element::Visible, ItemChecker::Checkbox::Boolean] }, checkbox: { hash: [ItemChecker::Element::Visible], visible: [ItemChecker::Element::Visible], invisible: [ItemChecker::Element::Invisible], boolean: [ItemChecker::Element::Visible, ItemChecker::Checkbox::Boolean] }, array: { array: [ItemChecker::Array::Array], string: [ItemChecker::Array::String], empty: [ItemChecker::Array::Empty], regexp: [ItemChecker::Array::Regexp], number: [ItemChecker::Elements::Number] }, boolean: { boolean: [ItemChecker::Any::Any] }, other: { number: [ItemChecker::Any::Any], other: [ItemChecker::Any::Any] }, string: { string: [ItemChecker::String::String], empty: [ItemChecker::String::Empty], regexp: [ItemChecker::String::Regexp] }, nil: { string: [ItemChecker::Nil::String], regexp: [ItemChecker::Nil::Regexp] } }.freeze
Class Method Summary collapse
- .checkers(_node, element, expectation, item_type) ⇒ Object
- .raise_bad_element(element) ⇒ Object
- .raise_bad_expectation(element, expectation) ⇒ Object
Class Method Details
.checkers(_node, element, expectation, item_type) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/prism_checker/check_dispatcher.rb', line 116 def self.checkers(_node, element, expectation, item_type) expectation_type = ExpectationClassifier.classify(expectation) element_expectations = CHECK_MAP[item_type] raise_bad_element(element) unless element_expectations checkers = element_expectations[expectation_type] raise_bad_expectation(element, expectation) unless checkers checkers end |
.raise_bad_element(element) ⇒ Object
130 131 132 133 |
# File 'lib/prism_checker/check_dispatcher.rb', line 130 def self.raise_bad_element(element) error = "Don't know how to check #{element.class.name}" raise Node::BadExpectation, error end |
.raise_bad_expectation(element, expectation) ⇒ Object
135 136 137 138 139 |
# File 'lib/prism_checker/check_dispatcher.rb', line 135 def self.raise_bad_expectation(element, expectation) element_class = element.class.name || element.class.ancestors.map(&:name).compact.first || '<Unknown>' error = "Don't know how to compare #{element_class} with #{expectation.class.name}" raise Node::BadExpectation, error end |