Class: Webrat::Matchers::HasContent
- Defined in:
- lib/webrat/core/matchers/have_content.rb
Overview
:nodoc:
Instance Method Summary collapse
- #content_message ⇒ Object
-
#failure_message ⇒ Object
Returns String:: The failure message.
-
#initialize(content) ⇒ HasContent
constructor
A new instance of HasContent.
- #matches?(stringlike) ⇒ Boolean
-
#negative_failure_message ⇒ Object
Returns String:: The failure message to be displayed in negative matches.
- #squeeze_space(inner_text) ⇒ Object
Constructor Details
#initialize(content) ⇒ HasContent
Returns a new instance of HasContent.
5 6 7 |
# File 'lib/webrat/core/matchers/have_content.rb', line 5 def initialize(content) @content = content end |
Instance Method Details
#content_message ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/webrat/core/matchers/have_content.rb', line 42 def case @content when String "include \"#{@content}\"" when Regexp "match #{@content.inspect}" end end |
#failure_message ⇒ Object
Returns
- String
-
The failure message.
28 29 30 |
# File 'lib/webrat/core/matchers/have_content.rb', line 28 def "expected the following element's content to #{}:\n#{squeeze_space(@element)}" end |
#matches?(stringlike) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/webrat/core/matchers/have_content.rb', line 9 def matches?(stringlike) if Webrat.configuration.parse_with_nokogiri? @document = Webrat.nokogiri_document(stringlike) else @document = Webrat.hpricot_document(stringlike) end @element = Webrat::XML.inner_text(@document) case @content when String @element.include?(@content) when Regexp @element.match(@content) end end |
#negative_failure_message ⇒ Object
Returns
- String
-
The failure message to be displayed in negative matches.
34 35 36 |
# File 'lib/webrat/core/matchers/have_content.rb', line 34 def "expected the following element's content to not #{}:\n#{squeeze_space(@element)}" end |
#squeeze_space(inner_text) ⇒ Object
38 39 40 |
# File 'lib/webrat/core/matchers/have_content.rb', line 38 def squeeze_space(inner_text) inner_text.gsub(/^\s*$/, "").squeeze("\n") end |