Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created March 4, 2010 14:57
Show Gist options
  • Select an option

  • Save lukeredpath/321764 to your computer and use it in GitHub Desktop.

Select an option

Save lukeredpath/321764 to your computer and use it in GitHub Desktop.
def assert_select_elements_in_order(selector, values, options={})
options.reverse_merge!(:starting_from_index => 1)
values.each_with_index do |value, index|
position = options[:starting_from_index] + index
assert_select "#{selector}:nth-of-type(#{position})", value,
"Expected value at #{selector}:(n=#{position}) to be #{value}"
end
end
# <ul id="list">
# <li>Foo</li>
# <li>Bar</li>
# <li>Baz</li>
# </ul>
#
# assert_select_elements_in_order("#list li", %w{Foo Bar Baz})
#
# <ul id="list">
# <li>Not relevant</li>
# <li>Foo</li>
# <li>Bar</li>
# <li>Baz</li>
# </ul>
#
# assert_select_elements_in_order("#list li", %w{Foo Bar Baz}, :starting_at_index => 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment