Module: Cucumber::Rails::Capybara::SelectDatesAndTimes

Defined in:
lib/cucumber/rails/capybara/select_dates_and_times.rb

Overview

This module defines methods for selecting dates and times

Instance Method Summary collapse

Instance Method Details

#select_date(date, options) ⇒ Object

Select a Rails date. Options hash must include :from => label



7
8
9
10
11
12
13
14
# File 'lib/cucumber/rails/capybara/select_dates_and_times.rb', line 7

def select_date(date, options)
  date        = Date.parse(date)
  base_dom_id = get_base_dom_id_from_label_tag(options[:from])

  find(:xpath, ".//select[@id='#{base_dom_id}_1i']").select(date.year.to_s)
  find(:xpath, ".//select[@id='#{base_dom_id}_2i']").select(I18n.l date, format: '%B')
  find(:xpath, ".//select[@id='#{base_dom_id}_3i']").select(date.day.to_s)
end

#select_datetime(datetime, options) ⇒ Object

Select a Rails datetime. Options hash must include :from => label



26
27
28
29
# File 'lib/cucumber/rails/capybara/select_dates_and_times.rb', line 26

def select_datetime(datetime, options)
  select_date(datetime, options)
  select_time(datetime, options)
end

#select_time(time, options) ⇒ Object

Select a Rails time. Options hash must include :from => label



17
18
19
20
21
22
23
# File 'lib/cucumber/rails/capybara/select_dates_and_times.rb', line 17

def select_time(time, options)
  time        = Time.zone.parse(time)
  base_dom_id = get_base_dom_id_from_label_tag(options[:from])

  find(:xpath, ".//select[@id='#{base_dom_id}_4i']").select(time.hour.to_s.rjust(2, '0'))
  find(:xpath, ".//select[@id='#{base_dom_id}_5i']").select(time.min.to_s.rjust(2,  '0'))
end