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

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

Instance Method Summary collapse

Instance Method Details

#select_date(field, options = {}) ⇒ Object



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

def select_date(field, options = {})
  date        = Date.parse(options[:with])
  base_dom_id = get_base_dom_id_from_label_tag(field)

  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(field, options = {}) ⇒ Object



22
23
24
25
# File 'lib/cucumber/rails/capybara/select_dates_and_times.rb', line 22

def select_datetime(field, options = {})
  select_date(field, options)
  select_time(field, options)
end

#select_time(field, options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/cucumber/rails/capybara/select_dates_and_times.rb', line 14

def select_time(field, options = {})
  time        = Time.zone.parse(options[:with])
  base_dom_id = get_base_dom_id_from_label_tag(field)

  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