How to select date from a select box using Capybara in Rails 3?

后端 未结 11 1512
梦如初夏
梦如初夏 2020-12-05 10:27

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         


        
11条回答
  •  误落风尘
    2020-12-05 10:52

    Given the following Formtastic code renders Rails default date selector:

    = f.input :born_on, end_year: Time.now.year, start_year: 60.years.ago.year
    

    In your spec, break the date into separate calls to each individual select tag:

    select '1956', from: 'person_born_on_1i'
    select 'July', from: 'person_born_on_2i'
    select '9', from: 'person_born_on_3i'
    

    I don't like that this code is so aware of the HTML, but it does work with the versions of gems at this time.

    Gems:

    • Capybara 2.1.0
    • Formtastic 2.2.1
    • Rails 3.2.13
    • RSpec 2.13.0

提交回复
热议问题