テストの中でレコードの作成時間をちょっとずらしたい時などに,sleepを入れるという最悪な解決方法はやめてtravisjeffery/timecopを使うとよい.
実行後に時間を置きたいメソッドをFoo#bar
とすると以下のように書く.
some_spec.rb
class Foo
def bar_with_timeshift
val = bar_without_timeshift
Timecop.travel(Time.now + 10.seconds)
val
end
alias_method_chain :bar, :timeshift
end
timeshiftというかっこいい名前はmotemenさんのgist:325058から.