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 5 years have passed since last update.

"bundle exec rspec" RSpecのテストコードを利用したテストを実行する際にエラーが出てしまう

Posted at

##$ bundle exec rspecが実行できない

下記コマンドを実行する際に、

$ bundle exec rspec
Book:pictweet_exam2 YUKI$ bundle exec rspec
Unsupported rails environment for compass

An error occurred while loading ./spec/models/user_spec.rb.
Failure/Error:
  class User < ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
    has_many :tweets
  
    validates :nickname, presence: true, length: { maximum: 6 }

ActiveRecord::AdapterNotSpecified:
  'test' database is not configured. Available: ["default", "development"]
# ./app/models/user.rb:1:in `<top (required)>'
# ./config/routes.rb:2:in `block in <top (required)>'
# ./config/routes.rb:1:in `<top (required)>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/models/user_spec.rb:1:in `require'
# ./spec/models/user_spec.rb:1:in `<top (required)>'
No examples found.

Finished in 0.00046 seconds (files took 5.97 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

とのエラーが出てしまう。

もちろんgemはしっかり記述、、bundle installはできている

スクリーンショット 2019-06-12 20.15.43.png

エラーメッセージの中の、

'test' database is not configured. Available: ["default", "development"]

のが怪しそうと検索、testdatabaseを確認するも、、、

スクリーンショット 2019-06-12 20.17.24.png

ちゃんとある、、

##database.ymlの確認

スクリーンショット 2019-06-12 20.19.23.png

testの記述のインデントが問題でした、、

スクリーンショット 2019-06-12 20.21.40.png

##解決

なんて単純なの、、
でもエラーメッセージにヒントが出てこないので、随分と時間がかかってしまった。

Book:pictweet_exam2 YUKI$ bundle exec rspec
Unsupported rails environment for compass

User
  #create
    is invalid without a nickname

Finished in 0.00736 seconds (files took 7.8 seconds to load)
1 example, 0 failures
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?