LoginSignup
2
3

More than 5 years have passed since last update.

[Rails]テスト環境のdb:createができない

Posted at

ユーザー認証が必要なwebサービスを構築してみようかと思って、
数年ぶりにRailsを触ってみたらさっそく詰まりましたので、詰まったポイントと解消方法です。

今回実行した環境

OSバージョン: ubuntu(仮想環境)
Ruby: 2.1.2
Rails: 4.2.0

bin/rake db:create RAILS_ENV=test でエラー!!

$ bin/rake db:create RAILS_ENV=test

テスト用のデータベースを構築するために、上記のコマンドを打つのですが、エラーが出てなかなか進めませんでした…

出力されたエラー

DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). 
The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. 
Web Console is activated in the test environment,
 which is usually a mistake. To ensure it's only activated in development mode,
 move it to the development group of your Gemfile:

    gem 'web-console', group: :development

If you still want to run it the test environment (and know
what you are doing), put this in your Rails application
configuration:

    config.web_console.development_only = false

gemを追加する指示が出ているので、従って以下をGemfileに追加します。

Gemfile
group :development do
  gem 'web-console', '~> 2.0'
end

これだけだと、まだエラーが全て解消しません……

NoMethodError: undefined method `last_comment' for #<Rake::Application:...>

とりあえず、ググっていたら参考にしている本の著者のブログを見つけました。

「最初の RSpec テストが失敗する場合」
https://www.oiax.jp/books/rails_kochiku_guide/first_rspec_example_failure.html

  • Gemfile の末尾に gem 'rake', '< 11.0' という記述を加える
  • ターミナルで bundle update rake コマンドを実行する

こちらを実行した上で、再度、テスト環境のデータベースを作成するコマンドを入力すると、成功しました!

以上、エラー対処の記事でした。
参考にしている本の関係上いまさら、rails4の話って感じもありますが、徐々にバージョンもあげつつ、開発を進めたいなぁという心境です。

2
3
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
2
3