Class: Spec::Rails::Matchers::OptionsMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/matchers/options_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ OptionsMatcher

Returns a new instance of OptionsMatcher.



5
6
7
# File 'lib/matchers/options_matcher.rb', line 5

def initialize expected
  @expected = expected
end

Instance Method Details

#extract_html_content(html) ⇒ Object



22
23
24
25
# File 'lib/matchers/options_matcher.rb', line 22

def extract_html_content html
  doc = Hpricot.XML(html)
  doc.search("/option").map{|n| n.inner_text.strip}
end

#failure_messageObject



14
15
16
# File 'lib/matchers/options_matcher.rb', line 14

def failure_message
  "\nWrong option contents.\nexpected: #{@expected.inspect}\n   found: #{@actual.inspect}\n\n"
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/matchers/options_matcher.rb', line 9

def matches? response
  @actual = extract_html_content response.body
  @actual == @expected
end

#negative_failure_messageObject



18
19
20
# File 'lib/matchers/options_matcher.rb', line 18

def negative_failure_message
  "\nShould not have matched contents: #{@expected.inspect}\n\n"
end