Class: Suhyo::ViewMatchers::HaveOrderedContent
- Inherits:
-
Webrat::Matchers::HasContent
- Object
- Webrat::Matchers::HasContent
- Suhyo::ViewMatchers::HaveOrderedContent
- Defined in:
- lib/suhyo/view_matchers.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(content, options = {}) ⇒ HaveOrderedContent
constructor
A new instance of HaveOrderedContent.
- #matches?(stringlike) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #order_message ⇒ Object
Constructor Details
#initialize(content, options = {}) ⇒ HaveOrderedContent
Returns a new instance of HaveOrderedContent.
6 7 8 9 |
# File 'lib/suhyo/view_matchers.rb', line 6 def initialize(content, = {}) @content = content @options = end |
Instance Method Details
#failure_message ⇒ Object
30 31 32 |
# File 'lib/suhyo/view_matchers.rb', line 30 def "expected the following element's content to #{}:\n#{squeeze_space(@element)} #{}" end |
#matches?(stringlike) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/suhyo/view_matchers.rb', line 11 def matches?(stringlike) @document = Webrat::XML.document(stringlike) @element = @document.inner_text compacted = @element.gsub(/\s+/, ' ') if index = compacted.index(@content) if @options.has_key?(:before) @other_content_index = compacted.index([:before]) index < @other_content_index elsif @options.has_key?(:after) @other_content_index = compacted.index([:after]) index > @other_content_index else true end else nil end end |
#negative_failure_message ⇒ Object
34 35 36 |
# File 'lib/suhyo/view_matchers.rb', line 34 def "expected the following element's content to not #{}:\n#{squeeze_space(@element)} #{}" end |
#order_message ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/suhyo/view_matchers.rb', line 38 def if @options.has_key?(:before) str = "before #{[:before]}" if @other_content_index.nil? str << " but #{[:before]} was not foudn" end elsif @options.has_key?(:after) str = "after #{[:after]}" if @other_content_index.nil? str << " but #{[:after]} was not foudn" end else nil end end |