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.
15 16 17 18 |
# File 'lib/suhyo/view_matchers.rb', line 15 def initialize(content, = {}) @content = content @options = end |
Instance Method Details
#failure_message ⇒ Object
47 48 49 |
# File 'lib/suhyo/view_matchers.rb', line 47 def "expected the following element's content to #{}#{}:\n\n#{squeeze_space(@element)}" end |
#matches?(stringlike) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/suhyo/view_matchers.rb', line 20 def matches?(stringlike) @document = Webrat::XML.document(stringlike) @element = @document.inner_text compacted = @element.gsub(/\s+/, ' ') if @main_content_index = compacted.index(@content) if @options.has_key?(:before) @other_content_index = compacted.index(@options[:before]) if @other_content_index.nil? return false else return @main_content_index < @other_content_index end elsif @options.has_key?(:after) @other_content_index = compacted.index(@options[:after]) if @other_content_index.nil? return false else return @main_content_index > @other_content_index end else return true end else return nil end end |
#negative_failure_message ⇒ Object
51 52 53 |
# File 'lib/suhyo/view_matchers.rb', line 51 def "expected the following element's content to not #{}#{}:\n\n#{squeeze_space(@element)}" end |
#order_message ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/suhyo/view_matchers.rb', line 55 def if @options.has_key?(:before) str = %Q{ before "#{@options[:before]}"} if !@main_content_index.nil? and @other_content_index.nil? str << %Q{ but "#{@options[:before]}" was not found} end return str elsif @options.has_key?(:after) str = %Q{ after "#{@options[:after]}"} if !@main_content_index.nil? and @other_content_index.nil? str << %Q{ but "#{@options[:after]}" was not found} end return str else return nil end end |