前提
docker、mysqlを使用しrailsでポートフォリオ用のweb appを作ろうとしており、githubにpushした際に自動でcircleCI上でrspec、rubocopが回るようにしようとしております。
circleCI CLIを用いてローカルでテストを実行した際には現れなかったエラーが出て困っております。
また、ローカルのdocker内でrspecを回した場合もエラーは表示されません。
実現したいこと
ここに実現したいことを箇条書きで書いてください。
- circleCI上でRSpecテストが通るようにしたい
発生している問題・エラーメッセージ
circleCIのdashboard上で確認したエラー
1Error reading historical timing data: invalid character ',' looking for beginning of value 2Requested weighting by historical based timing, but they are not present. Falling back to weighting by name. 3+ bundle exec rspec '' --profile 10 --format RspecJunitFormatter --out /tmp/test-results/rspec/results.xml --format progress 4 5An error occurred while loading .. 6Failure/Error: __send__(method, file) 7 8LoadError: 9 cannot load such file -- /home/circleci/project 10# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:2117:in `load' 11# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/rspec-core-3.12.0/lib/rspec/core/configuration.rb:2117:in `load_file_handling_errors' 12〜中略〜 13# /home/circleci/.rubygems/bin/bundle:25:in `load' 14# /home/circleci/.rubygems/bin/bundle:25:in `<main>' 15# 16# Showing full backtrace because every line was filtered out. 17# See docs for RSpec::Configuration#backtrace_exclusion_patterns and 18# RSpec::Configuration#backtrace_inclusion_patterns for more information. 19No examples found. 20 21 22Top 0 slowest examples (0 seconds, 0.0% of total time): 23 24Finished in 0.00006 seconds (files took 0.40131 seconds to load) 250 examples, 0 failures, 1 error occurred outside of examples
circleCI_CLIで行った結果
1circleci local execute -c .circleci/config.yml --job rspec 2 3~~~ 4====>> RSpec Tests 5 #!/bin/bash -eo pipefail 6#!/usr/bin/env bash 7 8if [ "$CIRCLE_NODE_TOTAL" -eq 1 ]; then 9 printf '%s\n' "Your job parallelism is set to 1." 10 printf '%s\n' "The split test by timings requires at least 2 nodes to generate historical timing data." 11 printf '%s\n' "Consider increasing your job parallelism to 2 or more." 12 printf '%s\n' "See https://circleci.com/docs/2.0/parallelism-faster-jobs/#using-the-circleci-cli-to-split-tests for more information." 13fi 14 15# Disable bash glob expansion 16# Without this, the glob parameter will be expanded before the split command is run 17set -o noglob 18 19if ! mkdir -p "$PARAM_OUT_PATH"; then 20 printf '%s\n' "Failed to create output directory: \"$PARAM_OUT_PATH\"" 21 exit 1 22fi 23 24# Backup IFS 25readonly old_ifs="$IFS" 26 27# Split globs per comma and run the CLI split command 28IFS="," 29read -ra globs <<< "$PARAM_INCLUDE" 30split_files=$(circleci tests glob "${globs[@]}" | circleci tests split --split-by=timings) 31 32# Convert list of test files to array 33# This is necessary because the split command returns a list of files separated by newline 34while IFS= read -r line; do test_files+=("$line"); done <<< "$split_files" 35 36# Rollback IFS 37IFS="$old_ifs" 38 39args=() 40 41if [ -n "$PARAM_ORDER" ]; then 42 args+=(--order "$PARAM_ORDER") 43fi 44 45if [ -n "$PARAM_TAG" ]; then 46 args+=(--tag "$PARAM_TAG") 47fi 48 49# Parse array of test files to string separated by single space and run tests 50# Leaving set -x here because it's useful for debugging what files are being tested 51set -x 52bundle exec rspec "${test_files[@]}" --profile 10 --format RspecJunitFormatter --out "$PARAM_OUT_PATH"/results.xml --format progress "${args[@]}" 53set +x 54 55Your job parallelism is set to 1. 56The split test by timings requires at least 2 nodes to generate historical timing data. 57Consider increasing your job parallelism to 2 or more. 58See https://circleci.com/docs/2.0/parallelism-faster-jobs/#using-the-circleci-cli-to-split-tests for more information. 59Error reading historical timing data: file does not exist 60Requested weighting by historical based timing, but they are not present. Falling back to weighting by name. 61+ bundle exec rspec spec/models/user_spec.rb --profile 10 --format RspecJunitFormatter --out /tmp/test-results/rspec/results.xml --format progress 62. 63 64Top 1 slowest examples (0.26576 seconds, 93.2% of total time): 65 User ユーザー登録 name、email、passwordとpassword_confirmationが存在すれば登録できること 66 0.26576 seconds ./spec/models/user_spec.rb:7 67 68Finished in 0.28512 seconds (files took 11.41 seconds to load) 691 example, 0 failures 70 71+ set +x 72~~~
該当のソースコード
circleci/config.yml
1version: 2.1 2orbs: 3 ruby: circleci/ruby@2.0.0 4jobs: 5 rubocop: 6 docker: 7 - image: 'cimg/ruby:2.7.6' 8 steps: 9 - checkout 10 - ruby/install-deps 11 - ruby/rubocop-check: 12 format: progress 13 label: Inspecting with Rubocop 14 15 rspec: 16 docker: 17 - image: 'cimg/ruby:2.7.6-node' 18 environment: 19 - RAILS_ENV: 'test' 20 - image: 'cimg/mysql:8.0' 21 environment: 22 - MYSQL_ALLOW_EMPTY_PASSWORD: 'true' 23 - MYSQL_ROOT_HOST: '%' 24 - MYSQL_DATABASE: ci_test 25 parallelism: 3 26 steps: 27 - checkout 28 - ruby/install-deps 29 - run: 30 command: 'dockerize -wait tcp://localhost:3306 -timeout 1m' 31 name: Wait for DB 32 - run: 33 name: Use specific database.yml 34 command: mv config/database.yml.ci config/database.yml 35 - run: 36 command: 'bundle exec rails db:schema:load --trace' 37 name: Database setup 38 - ruby/rspec-test 39 - run: ls 40 - run: ls .. 41 - run: ls ../circleci 42 - run: ls ../circleci/project 43 44workflows: 45 version: 2.1 46 build: 47 jobs: 48 - rubocop 49 - rspec
上記で参考にしたリンク
rubyのorb
https://circleci.com/developer/ja/orbs/orb/circleci/ruby
mysqlとの接続について
https://circleci.com/docs/ja/postgres-config/
config/database.yml.ci
1test: 2 adapter: mysql2 3 encoding: utf8mb4 4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 5 username: root 6 password: "" 7 host: 127.0.0.1 8 port: 3306 9 database: ci_test
spec/models/user_spec.rb
1require 'rails_helper' 2 3RSpec.describe User, type: :model do 4 let(:user) { create(:user) } 5 6 describe 'ユーザー登録' do 7 it "name、email、passwordとpassword_confirmationが存在すれば登録できること" do 8 expect(user).to be_valid 9 end 10 end 11end
試したこと
Failure/Error: __send__(method, file) LoadError: cannot load such file -- /home/circleci/project
という記述からbundle install周りがうまくいっていないのかと思い試行回数を増やすために
circleCI CLIでローカルに行った場合再現できなくなったため原因の検討がつかず困っております。
参考にしたサイトなどではorbを使わずに実装していることが多いためそちらで行うべきなのでしょうか?
また、rubyのorbのsample(https://circleci.com/developer/ja/orbs/orb/circleci/ruby)
において、
orb
node: circleci/node@x.y
の使用及び
- node/install-packages: cache-key: yarn.lock
の実行が行われており、postgresを使用する場合に行う操作かと思い省いているのですが
これが今回のエラーに関わる可能性はあるのでしょうか?
補足情報(FW/ツールのバージョンなど)
使用イメージ
cimg/ruby:2.7.6-node
cimg/mysql:8.0
gemfile
1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.7.6' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' 7gem 'rails', '~> 6.1.7' 8# Use mysql as the database for Active Record 9gem 'mysql2', '~> 0.5' 10# Use Puma as the app server 11gem 'puma', '~> 5.0' 12# Use SCSS for stylesheets 13#gem 'sass-rails', '>= 6' 14# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker 15gem 'webpacker', '~> 5.0' 16# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 17gem 'turbolinks', '~> 5' 18# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 19gem 'jbuilder', '~> 2.7' 20# Use Redis adapter to run Action Cable in production 21# gem 'redis', '~> 4.0' 22# Use Active Model has_secure_password 23# gem 'bcrypt', '~> 3.1.7' 24 25# Use Active Storage variant 26# gem 'image_processing', '~> 1.2' 27 28# Reduces boot times through caching; required in config/boot.rb 29gem 'bootsnap', '>= 1.4.4', require: false 30 31group :development, :test do 32 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 33 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 34 gem 'rspec-rails' 35 gem 'factory_bot_rails' 36 gem 'pry-rails' 37 gem 'rspec_junit_formatter' 38 gem 'rubocop-airbnb' 39end 40 41group :development do 42 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 43 gem 'web-console', '>= 4.1.0' 44 # Display performance information such as SQL time and flame graphs for each request in your browser. 45 # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md 46 gem 'rack-mini-profiler', '~> 2.0' 47 gem 'listen', '~> 3.3' 48 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 gem 'spring' 50end 51 52group :test do 53 # Adds support for Capybara system testing and selenium driver 54 gem 'capybara', '>= 3.26' 55 gem 'selenium-webdriver', '>= 4.0.0.rc1' 56 # Easy installation and use of web drivers to run system tests with browsers 57 gem 'webdrivers' 58end 59 60# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 61gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 62 63gem "aws-sdk", "~> 3.0" 64gem 'devise' 65gem 'omniauth-twitter' 66gem 'omniauth-google-oauth2' 67gem 'dotenv-rails' 68gem 'rails-i18n', '~> 6.0' 69gem 'devise-i18n'
M1mac使用
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。