質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Q&A

解決済

1回答

916閲覧

Ruby on Railsアップグレード時のRSpecの実行エラー

yasukun252

総合スコア34

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

0グッド

0クリップ

投稿2022/05/28 23:31

編集2022/05/28 23:40

前提・実現したいこと

Ruby on Railsを5.2.4から5.2.8にアップグレードして無事にアプリケーションは起動できるようになり、bundle exec rails db:migrateなどのコマンドも実行できます。
しかし、bundle exec rspec のコマンドでRSpecを実行すると以下のようなエラーが発生してRSpecが実行されません。
どのように対応すれば、RSpecは動くでしょうか?

% bundle exec rspec An error occurred while loading ./spec/controllers/administrators_controller_spec.rb. Failure/Error: require File.expand_path('../../config/environment', __FILE__) Psych::BadAlias: Cannot load database configuration: Unknown alias: default # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:430:in `visit_Psych_Nodes_Alias' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb:30:in `visit' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb:6:in `accept' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:35:in `accept' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:345:in `block in revive_hash' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:343:in `each' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:343:in `each_slice' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:343:in `revive_hash' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb:30:in `visit' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb:6:in `accept' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:35:in `accept' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:345:in `block in revive_hash' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:343:in `each' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:343:in `each_slice' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:343:in `revive_hash' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb:30:in `visit' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb:6:in `accept' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:35:in `accept' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:318:in `visit_Psych_Nodes_Document' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb:30:in `visit' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/visitor.rb:6:in `accept' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:35:in `accept' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych.rb:334:in `safe_load' # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych.rb:369:in `load' # ./vendor/bundle/ruby/2.6.0/gems/railties-5.2.8/lib/rails/application/configuration.rb:172:in `database_configuration' # ./vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.8/lib/active_record/railtie.rb:133:in `block (2 levels) in <class:Railtie>' # ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.8/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval' # ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.8/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook' # ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.8/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control' # ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.8/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook' # ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.8/lib/active_support/lazy_load_hooks.rb:43:in `block in on_load' # ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.8/lib/active_support/lazy_load_hooks.rb:42:in `each' # ./vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.8/lib/active_support/lazy_load_hooks.rb:42:in `on_load' # ./vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.8/lib/active_record/railtie.rb:132:in `block in <class:Railtie>' # ./vendor/bundle/ruby/2.6.0/gems/railties-5.2.8/lib/rails/initializable.rb:32:in `instance_exec' # ./vendor/bundle/ruby/2.6.0/gems/railties-5.2.8/lib/rails/initializable.rb:32:in `run' # ./vendor/bundle/ruby/2.6.0/gems/railties-5.2.8/lib/rails/initializable.rb:61:in `block in run_initializers' # ./vendor/bundle/ruby/2.6.0/gems/railties-5.2.8/lib/rails/initializable.rb:60:in `run_initializers' # ./vendor/bundle/ruby/2.6.0/gems/railties-5.2.8/lib/rails/application.rb:361:in `initialize!' # ./config/environment.rb:5:in `<top (required)>' # ./spec/rails_helper.rb:2:in `require' # ./spec/rails_helper.rb:2:in `<top (required)>' # ./spec/controllers/administrators_controller_spec.rb:1:in `require' # ./spec/controllers/administrators_controller_spec.rb:1:in `<top (required)>' # ------------------ # --- Caused by: --- # Psych::BadAlias: # Unknown alias: default # ./vendor/bundle/ruby/2.6.0/gems/psych-4.0.4/lib/psych/visitors/to_ruby.rb:430:in `visit_Psych_Nodes_Alias'

以下の記事を参考にして、Gemfileにgem 'psych', '~> 3.1'を追加しbundle installすると今度は以下のようなエラーになってしまいます。

% bundle install Warning: the running version of Bundler (1.17.2) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. Fetching gem metadata from https://rubygems.org/......... Fetching gem metadata from https://rubygems.org/. You have requested: psych ~> 3.1 The bundle currently has psych locked at 4.0.4. Try running `bundle update psych` If you are updating multiple gems in your Gemfile at once, try passing them all to `bundle update`

参考にした記事:https://teratail.com/questions/343233

また、RSpecのバージョンは以下のようになっております。(バージョンアップする前は、rspec-rails (4.0.0)でした。)

Gemfile.lock rspec-core (3.11.0) rspec-support (~> 3.11.0) rspec-expectations (3.11.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-mocks (3.11.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-rails (5.1.2) actionpack (>= 5.2) activesupport (>= 5.2) railties (>= 5.2) rspec-core (~> 3.10) rspec-expectations (~> 3.10) rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.11.0)

エラーが発生しているファイルは以下となります。

Rails_helper.rb ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) abort("The Rails environment is running in production mode!") if Rails.env.production? require 'spec_helper' require 'rspec/rails' require 'shoulda/matchers' Shoulda::Matchers.configure do |config| config.integrate do |with| with.test_framework :rspec with.library :active_record with.library :active_model with.library :action_controller with.library :rails end end # Coverage require 'simplecov' SimpleCov.start 'rails' ActiveRecord::Migration.maintain_test_schema! RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true config.infer_spec_type_from_file_location! config.filter_rails_from_backtrace! [:controller, :view, :request].each do |type| config.include ::Rails::Controller::Testing::TestProcess, type: type config.include ::Rails::Controller::Testing::TemplateAssertions, type: type config.include ::Rails::Controller::Testing::Integration, type: type end end Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

お手数をお掛けいたしますが、よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

以下を追記した状態でbundle updateで解決。
gem 'psych', '~> 3.1'

投稿2022/05/29 06:52

yasukun252

総合スコア34

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問