Class: PrismChecker::Node::Base
- Inherits:
-
Object
- Object
- PrismChecker::Node::Base
- Defined in:
- lib/prism_checker/node/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#checker ⇒ Object
readonly
Returns the value of attribute checker.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#expectation ⇒ Object
readonly
Returns the value of attribute expectation.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #build_expectation(expectation) ⇒ Object
- #check ⇒ Object
- #check_absence ⇒ Object
- #check_wrapper ⇒ Object
- #element ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(checker, parent, name, expectation) ⇒ Base
constructor
A new instance of Base.
- #path ⇒ Object
- #root? ⇒ Boolean
- #success? ⇒ Boolean
- #type(element) ⇒ Object
- #wait_until_true(timeout = @timeout, &block) ⇒ Object
Constructor Details
#initialize(checker, parent, name, expectation) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prism_checker/node/base.rb', line 16 def initialize(checker, parent, name, expectation) @parent = parent @checker = checker @name = name @expectation = build_expectation(expectation) @element = nil @status = 'Not checked' @error = nil @timeout = Capybara.default_max_wait_time @type = nil @checked_element = nil end |
Instance Attribute Details
#checker ⇒ Object (readonly)
Returns the value of attribute checker.
14 15 16 |
# File 'lib/prism_checker/node/base.rb', line 14 def checker @checker end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
14 15 16 |
# File 'lib/prism_checker/node/base.rb', line 14 def error @error end |
#expectation ⇒ Object (readonly)
Returns the value of attribute expectation.
14 15 16 |
# File 'lib/prism_checker/node/base.rb', line 14 def expectation @expectation end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/prism_checker/node/base.rb', line 14 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
14 15 16 |
# File 'lib/prism_checker/node/base.rb', line 14 def parent @parent end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/prism_checker/node/base.rb', line 14 def status @status end |
Instance Method Details
#build_expectation(expectation) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prism_checker/node/base.rb', line 29 def build_expectation(expectation) if expectation.is_a?(Symbol) && expectation.start_with?('absent') delay = expectation == :absent ? 0 : Integer(expectation.to_s.split('absent').last) return AbsenceExpectation.new(delay) end expectation rescue ArgumentError expectation end |
#check ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/prism_checker/node/base.rb', line 116 def check return check_absence if expectation.is_a?(AbsenceExpectation) check_wrapper do element = self.element element_type = type(element) checkers = CheckDispatcher.checkers(self, element, expectation, element_type) value = nil checkers.each do |checker| result = wait_until_true do element = self.element if element.is_a?(::Array) || element.is_a?(Capybara::Result) value = checker.value(element) checker.check(element, value, expectation) end unless result raise Node::CheckFail, checker.(element, value, expectation) end end @checked_element = element end end |
#check_absence ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/prism_checker/node/base.rb', line 88 def check_absence sleep expectation.delay check_wrapper do result = wait_until_true(0.1) do parent.element.public_send("has_no_#{name}?") end raise Node::CheckFail, 'Element is present' unless result end end |
#check_wrapper ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/prism_checker/node/base.rb', line 75 def check_wrapper yield @status = 'Ok' rescue Node::CheckFail => e @error = e @status = 'Fail' raise rescue StandardError => e @error = e @status = 'Error' raise end |
#element ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/prism_checker/node/base.rb', line 53 def element return @checked_element if @checked_element if root? @checker.item elsif parent.is_a?(Node::Hash) if parent.element.is_a?(Capybara::Node::Element) ElementWrapper.new(parent.element).send(@name) else parent.element.send(@name) end elsif parent.is_a?(Node::Array) parent.element[@name] end end |
#failure? ⇒ Boolean
45 46 47 |
# File 'lib/prism_checker/node/base.rb', line 45 def failure? @status == 'Fail' || @status == 'Error' end |
#path ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/prism_checker/node/base.rb', line 100 def path result = [] p = self while p.is_a? Base result << p.name p = p.parent end result.reverse end |
#root? ⇒ Boolean
41 42 43 |
# File 'lib/prism_checker/node/base.rb', line 41 def root? parent.is_a?(Checker) end |
#success? ⇒ Boolean
49 50 51 |
# File 'lib/prism_checker/node/base.rb', line 49 def success? @status == 'Ok' end |
#type(element) ⇒ Object
112 113 114 |
# File 'lib/prism_checker/node/base.rb', line 112 def type(element) @type ||= ItemClassifier.classify(element) end |
#wait_until_true(timeout = @timeout, &block) ⇒ Object
69 70 71 72 73 |
# File 'lib/prism_checker/node/base.rb', line 69 def wait_until_true(timeout = @timeout, &block) SitePrism::Waiter.wait_until_true(timeout, &block) rescue SitePrismCompat.timeout_error false end |