Cucumber step to test whether a select field is sorted

Updated . Posted . Visible to the public.

This step will pass if the specified select is sorted.

Then /^the "(.*?)" select should be sorted$/ do |label, negate|
  select = find_field(label)
  options = select.all('option').reject { |o| o.value.nil? }

  options.collect(&:text).each_cons(2) do |a,b|
    (a.text.downcase <=> b.text.downcase).should <= 0
  end
end

In conjunction with this custom matcher, the each_cons block can be replaced with:

options.should be_naturally_sorted

Usage

Then the "Organizations" select should be sorted

Depends on Capybara.


This step is now part of Spreewald Show archive.org snapshot .

Dominik Schöler
Last edit
Dominik Schöler
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2014-12-19 15:43)