3

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 01 2015 By inside MySQL

SELECT CURDATE();

This query returns "Jan 21 2015". Hence the test was failing.

So this brings to my questions.

  1. Is it a good practice to mock time in test cases?
  2. How to make sure that if time is mocked then MySQL is also receiving the same time?
Ajinkya Pisal
  • 551
  • 1
  • 6
  • 24
  • maybe don't use timecop, but adjust the time in the server (or in a virtual machine containing both ruby and mysql) – Jasen Jan 21 '15 at 05:29
  • @Jasen I can set system date using backticks like `date -s "somedate"`. But is it a good practice because it will be updating whole system's time which does not look good. – Ajinkya Pisal Jan 21 '15 at 05:31
  • 1
    that means you should not be testing on the live system. – Jasen Jan 21 '15 at 05:38
  • why SELECT curdate() then? are you testing changing the time in the internal clock? – John Ruddell Jan 21 '15 at 05:41

0 Answers0