Class: Spec::Rails::Matchers::ButtonMatcher
- Inherits:
-
Object
- Object
- Spec::Rails::Matchers::ButtonMatcher
- Defined in:
- lib/matchers/button_matcher.rb
Instance Method Summary collapse
- #extract_html_content(html) ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected_value) ⇒ ButtonMatcher
constructor
A new instance of ButtonMatcher.
- #matches?(response) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected_value) ⇒ ButtonMatcher
Returns a new instance of ButtonMatcher.
5 6 7 8 |
# File 'lib/matchers/button_matcher.rb', line 5 def initialize expected_value # @target_id = target_id @expected = expected_value end |
Instance Method Details
#extract_html_content(html) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/matchers/button_matcher.rb', line 23 def extract_html_content html doc = Hpricot.XML(html) # elements = doc.search("//input[@value='#{@expected}' & @type='button|submit']") # elements = doc.search("input[@value~='#{@expected}'][@type]") elements = doc.search("//input[@value='#{@expected}']").select{|e| ['submit', 'button'].include?(e['type'])} elements.map{|n| n['value']}.first end |
#failure_message ⇒ Object
15 16 17 |
# File 'lib/matchers/button_matcher.rb', line 15 def "\nWrong button value.\nexpected: #{@expected.inspect}\n found: #{@actual.inspect}\n\n" end |
#matches?(response) ⇒ Boolean
10 11 12 13 |
# File 'lib/matchers/button_matcher.rb', line 10 def matches? response @actual = extract_html_content response.body @actual == @expected end |
#negative_failure_message ⇒ Object
19 20 21 |
# File 'lib/matchers/button_matcher.rb', line 19 def "\nShould not have matched button: #{@target_id}, with text: '#{@expected}'\n\n" end |