0
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 1 year has passed since last update.

NameError:uninitialized constant Rspecの対処法

Posted at

ポートフォリオのテスト作成中に2つのエラーが発生しました。アウトプットも兼ねて解決法を記事にします。初学者ですので間違いもあるかと思いますが、多めに見てやってください🙇

エラーメッセージ

NameError:
  uninitialized constant Rspec
# ./spec/models/user_spec.rb:1:in `<top (required)>'
No examples found.

解決方法

なぜに?と思っていましたが、こちらの記事を参考に解決しました。
https://qiita.com/kaino5454/items/3d4e52c98bbe422ab65c
どうやらRSpecをRspecと小文字で書いていたことが原因のようです。

user.spec.rb
Rspec.describe User, type: :model do
#//省略
end

RSpec.describe User, type: :model do
#//省略
end

とても初歩的なミスでした汗。改めてbundle exec rspecを実行したら次はこんなエラーが、、、

エラーメッセージ

NameError:
  uninitialized constant User
# ./spec/models/user_spec.rb:1:in `<top (required)>'
No examples found.

解決方法

user.spec.rb
require 'rails_helper'

RSpec.describe User, type: :model do
#//省略
end

require 'rails_helper'を入れたら解決! 無事Rspecを通すことができました!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?