LoginSignup
0
0

More than 3 years have passed since last update.

Rails & JS系(Vueとか)のフレームワークで未来の時間のテストをする方法

Last updated at Posted at 2020-02-25

Rails側(サーバサイド)

Timecopを導入。
とりあえずGemfileに1行挿入。

Gemfile
(前略)
group :development, :test do
  (中略)
  gem 'timecop' #この一行をdevelopmentとかstagingの中に書く
  (後略)
end

Staging環境の場合は、当然staging.rbに記述してください。

config/environments/development.rb
Rails.application.configure do
(中略)
  config.after_initialize do
    t = Time.local(2023, 3, 25, 10, 5, 0) # 2023年3月25日10時5分0秒に固定
    Timecop.travel(t)
  end
end

JS側(クライアントサイド)

力技。OSの時間設定をいじれ!

取り敢えずMacだとシステム環境設定から。

スクリーンショット 2020-02-25 22.07.11.png

こんな時に便利

予定されたリリースをシミュレートしたり、月初の処理が適切に行われているか等の確認に使える。
翌月にならないとテストできない、リリース当日のぶっつけ本番は避けたいですよね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0