Questions tagged [timecop]

Timecop is a Ruby gem that provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.

Timecop is a Ruby gem that provides "time travel" and "time freezing" capabilities, to ease testing time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.

See https://github.com/travisjeffery/timecop

25 questions
1
vote
1 answer

Why does Timecop.freeze only work when I run my full spec suite?

I've got a large rails test suite and I'm using Timecop just once. it "should not include votes from today" do assert_equal 8, @answer.todays_score end it "should include today's votes tomorrow" do Timecop.travel(Date.today + 1) do …
doublea
  • 2,546
  • 1
  • 23
  • 35
0
votes
1 answer

Getting fractions of seconds difference instead of equal times when comparing dates with TimeCop

I've TimeCop installed and using the travel: option with my tests but my tests seem to be failing when I know they shouldn't be. I thought it was my code but it seems that I'm getting fractions of a second added somewhere which is causing dates that…
aarona
  • 35,986
  • 41
  • 138
  • 186
0
votes
1 answer

timecop.travel test returns false instead of true - rails

I am writing a unit test to check whether 24 hours have passed. If 24 hours have passed then it should return true here is my attempt test "messenger tag is more than 24 hours" do Timecop.travel 2.days.ago account =…
kahuria00
  • 317
  • 1
  • 5
  • 14
0
votes
1 answer

RSpec Timecop failures around Date appear to be timezone related

We have some tests (specs) that are failing around Date/Time. Guessing it's a UTC issue but not sure why these specs passed last time project was touched (~8-months ago)!?! #spec/features/comments/creation_spec.rb feature 'Comment creation', type:…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
0
votes
1 answer

Rspec surrounding shared_example with timecop

I am trying to wrap Timecop around a shared_example spec i wrote describe "timecop wrapping shared example" do Timecop.freeze(1.day.ago) do it_behaves_like "a shared example i would like to test using timecop" end end shared_examples "a…
amitben
  • 670
  • 10
  • 21
0
votes
1 answer

Timecop does not work with DateTime attributes defined in FactoryGirl

I have the following factory: FactoryGirl.define do factory :task do due_date 7.days.from_now end end In my specs, I'm using Timecop in this way: before do Timecop.freeze(Time.parse("Oct 5 2015")) end Time.now and Date.today are being…
Gerson Scanapieco
  • 723
  • 1
  • 7
  • 9
0
votes
1 answer

Timecop is not able to mock date correctly

I am using TimeCop Gem for testing time sensitive test cases. There is one file in the lib directory. It just contains string constants. Example. module DateStr SAMPLE = "Some date #{Date.current}" end In my cucumber test cases, this part of…
Ajinkya Pisal
  • 551
  • 1
  • 6
  • 24
0
votes
1 answer

freezing time in a capybara integration test

I'm writing an integration test using capybara and capybara-webkit where I need to compare two times and it randomly fails because sometimes the second passes and I have failures like expected: "Sep 01 2015 @ 04:49:17 employee_1" got: "Sep 01…
Sig
  • 5,476
  • 10
  • 49
  • 89
0
votes
3 answers

Timecop and Ruby 2.0.0

Can anyone suggest why this spec fails using Timecop 0.6.1 and Ruby 2.0.0? (It passes using Timecop 0.4.5 and Ruby 1.9.3) require 'timecop' require 'spec_helper' describe Class do it "freezes time" do Timecop.freeze Date.new(2012,7,1) do …
Mike
  • 9,692
  • 6
  • 44
  • 61
0
votes
1 answer

Unexpected Rspec Results using Timecop

Here is the basic idea of the spec: before :each do Timecop.freeze(Time.local(2012, 07, 01, 12, 0, 0)) #frozen at July 1st, 2012 at noon #create record code end it 'shows how long ago the message was recieved' do …
DVG
  • 17,392
  • 7
  • 61
  • 88
1
2