I\'m writing a spec for a controller in Rails 3 project using RSpec and Capybara, and I want to select current date from a select box. I tried:
select Date.t
with credit to Markus Hartmair for an excellent solution, I prefer to use labels as selectors because of improved readability. So my version of his helper module is:
module SelectDateHelper
def select_date(date, options = {})
field = options[:from]
base_id = find(:xpath, ".//label[contains(.,'#{field}')]")[:for]
year, month, day = date.split(',')
select year, :from => "#{base_id}_1i"
select month, :from => "#{base_id}_2i"
select day, :from => "#{base_id}_3i"
end
end
call it like this:
select_date "2012,Jan,1", :from => "From date"