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

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

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

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

RSpec

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

Ruby on Rails

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

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

Circle CI

Circle CIは、クラウド上に簡単にCI環境を構築できるWebサービスです。GitHubと連携させ、CIしたいリポジトリーを選択しビルド・テストを行います。チャット等を利用して結果を確認することが可能です。

Q&A

解決済

1回答

1068閲覧

CircleCIで、RailsのRspecを実行したいが、rake db:createでエラーになる

mkmk4423

総合スコア5

Ruby

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

RSpec

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

Ruby on Rails

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

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

Circle CI

Circle CIは、クラウド上に簡単にCI環境を構築できるWebサービスです。GitHubと連携させ、CIしたいリポジトリーを選択しビルド・テストを行います。チャット等を利用して結果を確認することが可能です。

0グッド

0クリップ

投稿2019/11/19 06:55

CircleCIで、bitbuketへのpush時に、テストを自動で行いたいのですが、
bundle ecec rake db:createコマンド実行時に
"NoMethodError: undefined method `[]' for nil:NilClass"
と、エラーが出てしまいます。

エラーを検索してみても、解決策が見つからず。どこに原因があるのかも見当がつきません、、、
どなたか見当がつく方がいらっしゃいましたら、ご教授お願いいたします。

発生しているエラー

#!/bin/bash -eo pipefail bundle exec rake db:create 2019-11-19 06:48:28 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead. rake aborted! NoMethodError: undefined method `[]' for nil:NilClass /home/circleci/repo/config/initializers/devise.rb:20:in `block in <main>' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/devise-4.7.1/lib/devise.rb:311:in `setup' /home/circleci/repo/config/initializers/devise.rb:5:in `<main>' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `block in load' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `load' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:657:in `block in load_config_initializer' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications.rb:170:in `instrument' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:656:in `load_config_initializer' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:613:in `each' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:613:in `block in <class:Engine>' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `each' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:50:in `tsort_each_child' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!' /home/circleci/repo/config/environment.rb:7:in `<main>' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:520:in `block in run_tasks_blocks' /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rake-13.0.0/exe/rake:27:in `<top (required)>' /usr/local/bin/bundle:23:in `load' /usr/local/bin/bundle:23:in `<main>' Tasks: TOP => db:create => db:load_config => environment (See full trace by running task with --trace) Exited with code 1

コード

circleci/config.yml

version: 2 jobs: rubocop: docker: - image: circleci/ruby:2.6.2-node-browsers-legacy environment: RAILS_ENV: test POSTGRES_HOST: 127.0.0.1 - image: circleci/postgres:11.5 environment: POSTGRES_USER: postgres POSTGRES_DB: myapp_test working_directory: ~/repo steps: - checkout - restore_cache: keys: - v2-dependencies-{{ checksum "Gemfile.lock" }} # fallback to using the latest cache if no exact match is found - v2-dependencies- - run: bundle install --jobs=4 --retry=3 --path vendor/bundle - save_cache: paths: - ./vendor/bundle key: v2-dependencies-{{ checksum "Gemfile.lock" }} # Rubocop - run: name: Rubocop command: bundle exec rubocop --auto-correct rspec: docker: - image: circleci/ruby:2.6.2-node-browsers-legacy environment: RAILS_ENV: test POSTGRES_HOST: 127.0.0.1 - image: circleci/postgres:11.5-alpine environment: POSTGRES_USER: postgres POSTGRES_DB: myapp_test working_directory: ~/repo steps: - checkout - restore_cache: keys: - v2-dependencies-{{ checksum "Gemfile.lock" }} - v2-dependencies- - run: name: install bundle command: | bundle install --jobs=4 --retry=3 --path vendor/bundle - save_cache: paths: - ./vendor/bundle key: v2-dependencies-{{ checksum "Gemfile.lock" }} - run: name: データベースの起動を待機 command: dockerize -wait tcp://127.0.0.1:5432 -timeout 1m #- run: mv config/database.yml.ci config/database.yml - run: bundle exec rake db:create - run: name: データベースのセットアップ command: bundle exec rake db:schema:load - run: name: gem install bundler command: gem install bundler # Align chrome-driver's version installed by chromedriver-helper - run: name: rspecを実行 command: bundle exec rspec - store_artifacts: path: tmp/screenshots/ destination: capybara workflows: version: 2 rubocop_rspec: jobs: - rubocop - rspec: requires: - rubocop

database.yml

default: &default adapter: postgresql encoding: unicode host: db username: postgres password: pool: 5 development: <<: *default database: myapp_development test: <<: *default database: myapp_test

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

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

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

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

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

guest

回答1

0

自己解決

こちら、Dockerで開発していたのですが、hostを、コンテナのエイリアスであるdbで指定していたため、エラーが起きていたようです、
database.ymlを以下のように変更

(省略) test: <<: *default host: <%= ENV.fetch("POSTGRES_HOST") { 'db' } %> database: myapp_test

このようにしたら、無事に、CIが通りました!

投稿2019/12/24 02:08

mkmk4423

総合スコア5

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問