Class: Utensils::CustomMatchers::Ordered

Inherits:
Object
  • Object
show all
Defined in:
lib/utensils/custom_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Ordered

Returns a new instance of Ordered.



122
123
124
125
126
127
# File 'lib/utensils/custom_matchers.rb', line 122

def initialize(args)
  @within = args.pop[:within]
  @selectors = args.map do |selector|
    selector.is_a?(String) ? selector : '#' + ApplicationController.helpers.dom_id(selector)
  end
end

Instance Method Details

#failure_messageObject



137
138
139
# File 'lib/utensils/custom_matchers.rb', line 137

def failure_message
  "expected #{@page.body} to have elements in this order: #{@selectors.inspect}"
end

#failure_message_when_negatedObject



141
142
143
# File 'lib/utensils/custom_matchers.rb', line 141

def failure_message_when_negated
  "expected #{@page.body} to not have elements in this order: #{@selectors.inspect}"
end

#matches?(page) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
135
# File 'lib/utensils/custom_matchers.rb', line 129

def matches?(page)
  @page = page
  @selectors.each_with_index do |selector,i|
    return false unless @page.has_css?("#{@within} #{selector}:nth-child(#{i+1})")
  end
  true
end