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