Check if selected date is correct with cucumber

The default web steps provided by cucumber provide a way to check the content of a text field : the "..." field should contain "...", but how to check if the date selected by default in a form is correct ?

To describe some of the features of the coming PigeBox web interface, we needed something like : the "..." datetime should contain "17:00:00".

Even if webrat doesn’t provide the builtin method to “read” a Rails datetime select, this piece of code adds the method selected_datetime to webrate scope.

With this small webrat extension, the following step becomes possible :

Then /^the "([^\"]*)" datetime should contain "([^\"]*)"$/ do |field, value|
  selected_datetime(:from => field).should == Time.parse(value)
end

In our case, it makes possible this kind of scenario :

  Scenario: Create a chunk with a single label
    Given a label exists with timestamp: "17:00:00"
    And that label is selected
    When I follow "Nouvel extrait à partir de ce repère"
    Then I should be on the new chunk page
    And the "Horaire de début" datetime should contain "17:00:00"
    And the "Horaire de fin" datetime should contain "17:00:00"

The complete gist is available.