zendesk/biz

TDD + Biz

jlanatta opened this issue · 3 comments

We are using TDD and we are trying to find out a way to mock dates in a way that works with biz. Do you know any solution that would work?

In particular we have a "expire date" set in working hours in our task model and we need to test our methods to see if a task is expired or not and all the things that are done if so.

Thanks!

Hey there! I'd be happy to help, but I'm having a little trouble envisioning how you're using biz in this case.

Do you have some example code (production and test) that you could provide? In general, you should be able to inject plain ol' Date and Time objects while testing.

Hi @craiglittle, I was trying to write a test for the following method:

  def is_due?(task)
    due_date = Biz.time(task.due_time, :hours).after(task.created_at)
    due_date <= Time.now
  end

Thanks to @Intrepidd now I'm using #travel_to (blog entry about it), available on rails >= 4.1 which solved the problem of setting a fixed date to be able to write test cases for that method.

Thanks for the quick response!

Ah, gotcha! timecop is another good option when you're not in a Rails environment.

Glad you got it worked out!