Class: RoadForest::Testing::HaveXpath
- Inherits:
-
Object
- Object
- RoadForest::Testing::HaveXpath
- Defined in:
- lib/roadforest/test-support/matchers.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#found ⇒ Object
Returns the value of attribute found.
-
#trace ⇒ Object
readonly
Returns the value of attribute trace.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#xpath ⇒ Object
readonly
Returns the value of attribute xpath.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(xpath, value, trace) ⇒ HaveXpath
constructor
A new instance of HaveXpath.
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(xpath, value, trace) ⇒ HaveXpath
Returns a new instance of HaveXpath.
115 116 117 |
# File 'lib/roadforest/test-support/matchers.rb', line 115 def initialize(xpath, value, trace) @xpath, @value, @trace = xpath, value, trace end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
118 119 120 |
# File 'lib/roadforest/test-support/matchers.rb', line 118 def actual @actual end |
#found ⇒ Object
Returns the value of attribute found.
119 120 121 |
# File 'lib/roadforest/test-support/matchers.rb', line 119 def found @found end |
#trace ⇒ Object (readonly)
Returns the value of attribute trace.
118 119 120 |
# File 'lib/roadforest/test-support/matchers.rb', line 118 def trace @trace end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
118 119 120 |
# File 'lib/roadforest/test-support/matchers.rb', line 118 def value @value end |
#xpath ⇒ Object (readonly)
Returns the value of attribute xpath.
118 119 120 |
# File 'lib/roadforest/test-support/matchers.rb', line 118 def xpath @xpath end |
Instance Method Details
#description ⇒ Object
121 122 123 |
# File 'lib/roadforest/test-support/matchers.rb', line 121 def description "should match #{@xpath.inspect}" end |
#failure_message_for_should ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/roadforest/test-support/matchers.rb', line 144 def msg = case value when true "expected that #{xpath.inspect} would be present\nwas:\n #{found.inspect}\n" when false "expected that #{xpath.inspect} would be absent\nwas:\n #{found.inspect}\n" else "expected that #{xpath.inspect} would be\n #{value.inspect}\nwas:\n #{found.inspect}\n" end msg += "in:\n" + actual.to_s msg += "\nDebug:#{trace.join("\n")}" if trace msg end |
#failure_message_for_should_not ⇒ Object
159 160 161 162 163 |
# File 'lib/roadforest/test-support/matchers.rb', line 159 def msg = "expected that #{xpath.inspect} would not be #{value.inspect} in:\n" + actual.to_s msg += "\nDebug:#{trace.join("\n")}" if trace msg end |
#matches?(actual) ⇒ Boolean
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/roadforest/test-support/matchers.rb', line 125 def matches?(actual) @actual = actual @doc = Nokogiri::HTML.parse(actual) @namespaces = @doc.namespaces.merge("xhtml" => "http://www.w3.org/1999/xhtml", "xml" => "http://www.w3.org/XML/1998/namespace") self.found = @doc.root.at_xpath(xpath, @namespaces) case value when false found.nil? when true !found.nil? when Array found.to_s.split(" ").include?(*value) when Regexp found.to_s =~ value else found.to_s == value end end |