Class: Suhyo::ViewMatchers::HaveOrderedContent

Inherits:
Webrat::Matchers::HasContent
  • Object
show all
Defined in:
lib/suhyo/view_matchers.rb

Instance Method Summary collapse

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, options = {})
	@content = content
	@options = options
end

Instance Method Details

#failure_messageObject



30
31
32
# File 'lib/suhyo/view_matchers.rb', line 30

def failure_message
	"expected the following element's content to #{content_message}:\n#{squeeze_space(@element)} #{order_message}"
end

#matches?(stringlike) ⇒ Boolean

Returns:

  • (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(options[:before])
			index < @other_content_index
		elsif @options.has_key?(:after)
			@other_content_index = compacted.index(options[:after])
			index > @other_content_index
		else
			true
		end
	else
		nil
	end
end

#negative_failure_messageObject



34
35
36
# File 'lib/suhyo/view_matchers.rb', line 34

def negative_failure_message
	"expected the following element's content to not #{content_message}:\n#{squeeze_space(@element)} #{order_message}"
end

#order_messageObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/suhyo/view_matchers.rb', line 38

def order_message
	if @options.has_key?(:before)
		str = "before #{options[:before]}"
		if @other_content_index.nil?
			str << " but #{options[:before]} was not foudn"
		end
	elsif @options.has_key?(:after)
		str = "after #{options[:after]}"
		if @other_content_index.nil?
			str << " but #{options[:after]} was not foudn"
		end
	else
		nil
	end
end