Class: ShouldPricot::ElementAssertion
- Inherits:
-
Object
- Object
- ShouldPricot::ElementAssertion
show all
- Defined in:
- lib/should_pricot/element_assertion.rb
Instance Method Summary
collapse
Constructor Details
#initialize(selector, html, test_instance) ⇒ ElementAssertion
Returns a new instance of ElementAssertion.
3
4
5
6
7
|
# File 'lib/should_pricot/element_assertion.rb', line 3
def initialize(selector, html, test_instance)
@selector = selector
@test = test_instance
@element = html.at(selector)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
35
36
37
|
# File 'lib/should_pricot/element_assertion.rb', line 35
def method_missing(method, *args)
@test.send method, *args
end
|
Instance Method Details
#should_be(expected) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/should_pricot/element_assertion.rb', line 9
def should_be(expected)
should_be_present
if expected.is_a? Regexp
assert_match expected, @element.inner_html.strip
else
assert_equal expected, @element.inner_html.strip
end
end
|
#should_be_missing ⇒ Object
29
30
31
|
# File 'lib/should_pricot/element_assertion.rb', line 29
def should_be_missing
assert @element.nil?, "element : '#{@selector}' is present"
end
|
#should_be_present ⇒ Object
25
26
27
|
# File 'lib/should_pricot/element_assertion.rb', line 25
def should_be_present
assert @element.is_a?(Hpricot::Elem), "element : '#{@selector}' is missing"
end
|
#should_contain(expected) ⇒ Object
19
20
21
22
23
|
# File 'lib/should_pricot/element_assertion.rb', line 19
def should_contain(expected)
should_be_present
assert_match expected, @element.inner_html.strip
end
|