Class: MerbExt::SpecCustomMatchers::HaveList

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-ext/spec_custom_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ HaveList

Returns a new instance of HaveList.



56
57
58
59
# File 'lib/merb-ext/spec_custom_matchers.rb', line 56

def initialize(list)
  @lsit = list
  @list_items = list.split("\n").map {|e| e.strip}
end

Instance Method Details

#failure_messageObject



70
71
72
# File 'lib/merb-ext/spec_custom_matchers.rb', line 70

def failure_message
  "expected #{@target.body} to look like: #{@list}"
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
# File 'lib/merb-ext/spec_custom_matchers.rb', line 61

def matches?(target)
  @target = target

  @list_items.each_with_index do |item, index|
    matcher = ::Webrat::Matchers::HaveXpath.new("//ul//li[#{index+1}][contains(. ,'#{item}')]")
    return false unless matcher.matches?(target)
  end
end