Skip to content

Instantly share code, notes, and snippets.

@fiedl
Created October 22, 2015 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiedl/b0311af7624591071705 to your computer and use it in GitHub Desktop.
Save fiedl/b0311af7624591071705 to your computer and use it in GitHub Desktop.
Fixing time zone issue in specs between 0:00 and 2:00

Some of our specs failed between 0:00 and 2:00, but succeeded otherwise.

The issue had been that to_date itself does not consider the timezone, such that we had to replace expressions like

I18n.localize @some_datetime.to_date

with

I18n.localize @some_datetime.in_time_zone(TEST_TIMEZONE).to_date

in order to have the specs succeed at any time.

require 'spec_helper'
describe "something that depends on localized dates" do
# ...
it 'should be possible to change the date' do
within('#corporate_vita') do
@valid_from_formatted = I18n.localize @membership.valid_from.in_time_zone(TEST_TIMEZONE).to_date
page.should have_content @valid_from_formatted
@new_date = 10.days.ago.in_time_zone(TEST_TIMEZONE).to_date
fill_in "valid_from_localized_date", with: I18n.localize(@new_date)
page.should have_no_selector("input")
page.should have_content I18n.localize(@new_date)
end
end
end
I18n.default_locale = :de
I18n.locale = :de
TEST_TIMEZONE = "Berlin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment