I have a form with a date_select which shows 3 selectboxes for day, month and year. I have a rspec integration test where I want to select today’s date with capybara. So I have to split Date.today into a day, month and year. What’s a good way to do this? I could do some string splits, but maybe there is a more sophisticated way to do?
Here you see the capybara code to select the date hard coded:
select("13", :from => "visit_visit_date_3i")
select("July", :from => "visit_visit_date_2i")
select("2012", :from => "visit_visit_date_1i")
There are methods for extracting date parts from a Date object. The date class also has some constant arrays that make it easy to convert things like months and days of the week to their English versions.
Thus:
All this is in the docs for Date, which are located here.