سؤال

In my application.rb, I have

config.time_zone = "Pacific Time (US & Canada)"

And this works correctly in development/test, and production servers. However when I push to Travis-CI, it appears to be localized to UTC for example the output of I18n.l Time.now.

Is there something different about the Travis-CI ruby/rails environment?

هل كانت مفيدة؟

المحلول 2

The way I accomplish setting the timezone is in the before_script section of the travis.yml

They give you root access to the VM running your project, so you can simply set the OS timezone that ruby uses:

    before_script:
      - echo 'Canada/Pacific' | sudo tee /etc/timezone
      - sudo dpkg-reconfigure --frontend noninteractive tzdata

If you wish, you can also force an update by adding this below:

      - sudo ntpdate ntp.ubuntu.com

نصائح أخرى

This worked for me:

before_install:
- export TZ=Australia/Canberra

to check that is correct you can output the date with this:

- date

I had a similar problem and solved it.

On development my time is +10 GMT.

On Travis my time is +11 GMT.

before_script:
  - export TZ=Australia/Melbourne

I used Time Cop gem to test time depended code. Here is how i changed what the time is set too on Travis.

Here is an example test:

require 'spec_helper'
context "during the week after 11:00am for Morning Follow Up Call" do
  before do
    valid_prospect_params["treatment_enquiry_form"]["contact_time"] = "10:00 am"
    freeze_time = Time.local(2015, 11, 18, 11, 01, 0)
    change_time(freeze_time)
    post :create_prospect, valid_prospect_params
    reset_time
  end

  it "creates follow up activities" do
    expect(prospect_followup_activities).to eq(3)
  end

  it "creates follow_up_call for the next day in the morning " do
    expect(first_call.scheduled_for.to_s).to  eq("2015-11-19 10:00:00 +1100")
  end
end

Here is is how i changed the time on Travis. I have 2 methods.

def change_time(freeze_time)
  if Time.now.strftime("%Z") == "AEDT"
    Timecop.freeze(freeze_time + 1.hours)
  else
    Timecop.freeze(freeze_time)
  end
end

def reset_time
  Timecop.return
end
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top