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
19
votes
3 answers

Rails - Testing a method that uses DateTime.now

I have a method that uses DateTime.now to perform a search on some data, I want to test the method with various dates but I don't know how to stub DateTime.now nor can I get it working with Timecop ( if it even works like that ). With time cop I…
raphael_turtle
  • 7,154
  • 10
  • 55
  • 89
11
votes
2 answers

Capybara::FrozenInTime error in integration specs using Rspec + Timecop + Capybara + Capybara Webkit

I'm seeing an error in some integration specs, using rspec, capybara, capybara-webkit and timecop. Capybara::FrozenInTime: time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling…
hsgubert
  • 2,266
  • 1
  • 22
  • 23
3
votes
1 answer

How to control time for capybara / phantomjs tests

I want to test that some deadlines are getting displayed to users correctly in different timezones and at different times of day. My tests are using capybara+rspec+phantomjs. I am passing a block to Timecop.travel(datetime) and the code in the test…
Bee
  • 14,277
  • 6
  • 35
  • 49
3
votes
0 answers

Mocking time in mysql

Problem: I am currently using Time Cop gem for mocking time in cucumber test cases. There is one test case that is getting failed because of MySQL is not getting the time set by Time Cop. Lets say. System date is = Jan 21 2015 After Time Cop = Feb…
Ajinkya Pisal
  • 551
  • 1
  • 6
  • 24
2
votes
2 answers

Ruby constant date variable with respect to timecop in rspec

Hi I have a Ruby class with some constant variables using Date: START_DATE = Date.current.at_beginning_of_month.in_time_zone + 2.days LAST_DATE = Date.current.at_beginning_of_month.in_time_zone + 10.days and I have some methods which uses this date…
nrmb
  • 460
  • 1
  • 6
  • 17
2
votes
1 answer

Timecop with Factory_girl: factory not sequencing date attribute as expected

I am using the timecop gem in order to stub out dates. I am also using factory_girl in order to make creating objects for my specs easier. Here is my factory: FactoryGirl.define do factory :fiscal_year do start_date {Date.today} end_date…
Neil
  • 4,578
  • 14
  • 70
  • 155
2
votes
1 answer

Strong Parameters with API

NOTE: This question has been answered (by me), and the information below turned out to be a red herring. I leave it here in case it helps someone. See below for the answer! I'm upgrading all of my controllers to strong parameters, and I'm running…
2
votes
0 answers

Is there a way of testing for cookie expiry in cucumber tests?

I want to set a 'remember me' cookie on my website with a 2 week expiry rather than permanent and want to test for this. My attempt at this has so far been unsuccessful. Here's my cucumber scenario; Scenario: A user logs in with the remember me…
brad
  • 9,573
  • 12
  • 62
  • 89
1
vote
1 answer

Ruby gem timecop wrong delay between two dates after travel

I am using the helpful gem timecop (https://github.com/travisjeffery/timecop) for my tests with rspec and today an old unchanged test is breaking. I might be mistaken in the way I am using it but using pry I printed the following: Time.zone.now =>…
Thib
  • 41
  • 5
1
vote
1 answer

Timecop doesn't work with cucumber capybara

Sorry for my english, it's not my native language I have some time sensetive test. It's about some alert message when before event left less than 24h or more than 24h. Some part of my code to find required events left_less_than_24_hours_to_event =…
1
vote
1 answer

Protobuf-related unit tests passing on my local machine but failing in Jenkins pipeline

I have a set of unit tests for serializer objects in my Rails application. These serializer objects use the google-protobuf (~> 3.5) gem, including the Google::Protobuf::Timestamp object. For time-related attributes (like…
1
vote
1 answer

Devise, Capybara - 'UncaughtThrowError (uncaught throw :warden)' possibly due to Timecop

Some of my feature specs are failing intermittently. Our specs are setting the base-line to be in the past. I have found the following: Error thrown is: UncaughtThrowError (uncaught throw :warden): [#B3FBC85E07A6] devise (4.3.0)…
Harry V
  • 73
  • 1
  • 1
  • 6
1
vote
0 answers

Webdriver in Python - Executing Function from External Script

How do I execute a function located in an external JavaScript using webdriver in python? The JavaScript is used to overwrite JavaScripts internal DateTime object to give an altered browser time for unit testing. I like to use sinonfaketimers.js for…
John Slathon
  • 353
  • 2
  • 6
  • 15
1
vote
1 answer

Groovy/Grails equivalent of Ruby/Rails' 'timecop' gem

does anybody know if there is something for Groovy/Grails similar to the rubygem timecop I'm working on tests for a Grails project where I would like to mock DateTime classes in the same way the gem does. Just wondering if anybody had already done…
David West
  • 2,256
  • 6
  • 32
  • 62
1
vote
1 answer

Sidetiq testing with TimeCop

I'm trying to write some test for my Sidekiq jobs that use Sidetiq and I can't seem to get it to work. I've found an issue on the sidetiq repo dealing with this problem but no one has answered it so I thought I could bring it to stackoverflow to get…
meatherly
  • 1,741
  • 2
  • 13
  • 16
1
2