LoginSignup
0
0

More than 3 years have passed since last update.

RSpecの単体テストにて"translation missing: ja.activerecord.○○"というエラーが出たときの対処法

Last updated at Posted at 2020-07-30

Deviseを日本語化したときのエラー。エラー画面はこんな感じ。
image.png

◆原因

どうやらdeviseのエラーメッセージを日本語化したことによって本来Deviseで用意されているエラー文(英語)テスト実行時のエラー文(devise.ja.yml)に相違が出てしまい、エラーになってしまってるぽい。

◆解決策

巷に落ちているdevise.ja.ymlの内容もそれぞれ引用元によって異なるため、このエラーが出た際にはdevise.ja.ymlに記述を追加する必要がある。

実際に記述を追加していく。
今回の場合エラー分が
expected [translation missing: ja.activerecord.errors.models.user.attributes.name.blank] to include "can't be blank"
なので

config/locals/devise.ja.yml
ja:
  activerecord:
    errors:
      models:
        user:
          attributes:
            name:
              blank: "が入力されていません"

と追記してあげる。

これで無事にテストが通るように!

参考にした記事

Devise日本語化後の「translation missing」に対処する

translationmissing:ja.activerecord.errors.models.hoge.attributes.base.restrict_dependent_destroy.many の対処方法

Createの際のエラーUser translation missing: ja.activerecord.errors.models.company.attributes.user.required

deviseを日本語化する

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