Class: Spec::Rails::Matchers::CheckBoxGroupMatcher
- Inherits:
-
Object
- Object
- Spec::Rails::Matchers::CheckBoxGroupMatcher
- Defined in:
- lib/matchers/check_box_group_matcher.rb
Instance Method Summary collapse
- #extract_html_content(html) ⇒ Object
- #failure_message ⇒ Object
-
#initialize(target_name, expected) ⇒ CheckBoxGroupMatcher
constructor
A new instance of CheckBoxGroupMatcher.
- #matches?(response) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(target_name, expected) ⇒ CheckBoxGroupMatcher
Returns a new instance of CheckBoxGroupMatcher.
6 7 8 9 |
# File 'lib/matchers/check_box_group_matcher.rb', line 6 def initialize target_name, expected @expected = expected @target_name = target_name end |
Instance Method Details
#extract_html_content(html) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/matchers/check_box_group_matcher.rb', line 24 def extract_html_content html doc = Hpricot.XML(html) # elements = doc.search('div input[type="checkbox"]') elements = doc.search('div/input') elements = elements.select{|n| n.elem? && n.get_attribute('type') == 'checkbox' && n.get_attribute('name') == @target_name} elements.map{|n| value = n.get_attribute('value'); [value, find_label(n)]} end |
#failure_message ⇒ Object
16 17 18 |
# File 'lib/matchers/check_box_group_matcher.rb', line 16 def "\nWrong check box group contents.\nexpected: #{@expected.inspect}\n found: #{@actual.inspect}\n\n" end |
#matches?(response) ⇒ Boolean
11 12 13 14 |
# File 'lib/matchers/check_box_group_matcher.rb', line 11 def matches? response @actual = extract_html_content response.body @actual == @expected end |
#negative_failure_message ⇒ Object
20 21 22 |
# File 'lib/matchers/check_box_group_matcher.rb', line 20 def "\nShould not have matched check box group: name: #{@target_name}, with: #{@expected.inspect}\n\n" end |