Sha256: 9575979ea118691210d26a1a9d5e7f6072f1f4a8048647dc25fa87e985ac77d1

Contents?: true

Size: 1.67 KB

Versions: 7

Compression:

Stored size: 1.67 KB

Contents

module Cucumber
  module Rails
    module Capybara
      module SelectDatesAndTimes
        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
      
        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
      
        def select_datetime(field, options = {})
          select_date(field, options)
          select_time(field, options)
        end

        private

        # @example "event_starts_at_"
        def get_base_dom_id_from_label_tag(field)
          find(:xpath, "//label[contains(., '#{field}')]")['for'].gsub(/(_[1-5]i)$/, '')
        end
      end
    end
  end
end

World(::Cucumber::Rails::Capybara::SelectDatesAndTimes)

When /^(?:|I )select "([^"]+)" as the "([^"]+)" time$/ do |time, selector|
  select_time(selector, :with => time)
end

When /^(?:|I )select "([^"]+)" as the "([^"]+)" date$/ do |date, selector|
  select_date(selector, :with => date)
end

When /^(?:|I )select "([^"]+)" as the "([^"]+)" date and time$/ do |datetime, selector|
  select_datetime(selector, :with => datetime)
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
casecumber-rails-1.0.2.1 lib/cucumber/rails/capybara/select_dates_and_times.rb
cucumber-rails-1.0.2 lib/cucumber/rails/capybara/select_dates_and_times.rb
cucumber-rails-1.0.1 lib/cucumber/rails/capybara/select_dates_and_times.rb
cucumber-rails-1.0.0 lib/cucumber/rails/capybara/select_dates_and_times.rb
cucumber-rails-0.5.2 lib/cucumber/rails/capybara/select_dates_and_times.rb
cucumber-rails-0.5.1 lib/cucumber/rails/capybara/select_dates_and_times.rb
cucumber-rails-0.5.0 lib/cucumber/rails/capybara/select_dates_and_times.rb