1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rails】RSpecでDeviceメール認証をクリアする方法

1
Posted at

実装例

userのサンプルデータを作成する段階で認証済にします。
factorybotのuser do内に追記するのみで、
テストコードには変更を加えませんので汎用的に使えるかと思います。

factorybot.rb
FactoryBot.define do
  factory :user do
    :
    :
    #下記1行を追加するだけ
    confirmed_at { Date.today }
  end
end

この状態でfactorybotを実行すれば
メール認証済の状態でサンプルデータを作ることができます。
参考:github.com/henrydjacob

その他の解決方法

テストコード内のbefore処理に記述する方法もありました。
参考:Rspecのrequest(Integration test)でDeviseのメール認証を回避する方法

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?