Tra*_*ick 7 ruby-on-rails circleci
我正在尝试将 Code Climate Test Reporter 添加到我们当前正在构建的 New Rails 应用程序中。
我在其他项目上设置了 Circleci,因此我修改了配置以适合该项目,但当 rspec 测试完成运行时,我继续收到以下错误。
69 file(s) with 100% coverage not shown
Traceback (most recent call last):
3: from /home/circleci/my-app/vendor/bundle/ruby/2.7.0/gems/simplecov-0.17.1/lib/simplecov/defaults.rb:29:in `block in <main>'
2: from /home/circleci/my-app/vendor/bundle/ruby/2.7.0/gems/simplecov-0.17.1/lib/simplecov.rb:205:in `run_exit_tasks!'
1: from /home/circleci/my-app/vendor/bundle/ruby/2.7.0/gems/simplecov-0.17.1/lib/simplecov.rb:224:in `process_result'
/home/circleci/my-app/vendor/bundle/ruby/2.7.0/gems/simplecov-0.17.1/lib/simplecov.rb:243:in `result_exit_status': undefined method `-' for nil:NilClass (NoMethodError)
Exited with code exit status 1
CircleCI received exit code 1
Run Code Online (Sandbox Code Playgroud)
有人见过这样的错误吗?如果是这样,对于让 Code Climate Test Reporter 与 CircleCI 正常工作有什么建议吗?
配置.yml
version: 2
jobs:
build:
parallelism: 1 # however many CPUs you need/pay for
#############################################
# Container Setup
#############################################
docker:
- image: circleci/ruby:2.7.2-node-browsers
environment:
RAILS_ENV: test
CC_TEST_REPORTER_ID: #########################
COVERAGE: true
- image: circleci/postgres:11 # database image
environment:
POSTGRES_USER: root
POSTGRES_DB: circle_test
POSTGRES_PASSWORD: circleci
- image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
environment:
discovery.type: single-node
- image: selenium/standalone-chrome-debug
name: selenium
ports:
- "4444:4444"
#############################################
# Build Steps
#############################################
steps:
- checkout
- run:
name: Configure secrets.yml
command: mv config/secrets.ci.yml config/secrets.yml
- run:
name: Configure database.yml
command: mv config/database.ci.yml config/database.yml
- run:
name: Configure application.yml
command: mv config/application.ci.yml config/application.yml
###########################################
# Bundler w/ caching
###########################################
- restore_cache:
keys:
- rails-bundle-{{ checksum "Gemfile.lock" }}
- rails-bundle-
- run:
name: Configure Bundler
command: |
echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
source $BASH_ENV
gem install bundler
- run:
name: Bundle Gems
command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
- save_cache:
key: rails-bundle-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
###########################################
# Apt Update and install packages
###########################################
- run:
name: apt update
command: sudo apt update
- run:
name: Install Packages
command: sudo apt-get install -y graphicsmagick ghostscript ffmpeg
- run:
name: Install Tesseract
command: sudo apt-get install -y libleptonica-dev libtesseract-dev tesseract-ocr
###########################################
# Code Climate
###########################################
- run:
name: Install Code Climate Test Reporter
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
###########################################
# Database
###########################################
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Load DB schema
command: bin/rails db:schema:load --trace
###########################################
# Run rspec in parallel
###########################################
- run:
name: Run rspec in parallel
command: |
mkdir -p test_results
./cc-test-reporter before-build
bundle exec rspec --profile 10 \
--format RspecJunitFormatter \
--out test_results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
- run:
name: Code Climate Test Coverage
command: |
./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
# Save test results for timing analysis
- store_test_results:
path: test_results
- deploy:
command: |
./cc-test-reporter sum-coverage --output - coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
Run Code Online (Sandbox Code Playgroud)
宝石文件
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.2'
# Rails
# ================================================================
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'rails', '~> 6.1', '>= 6.1.3'
gem 'webpacker', '~> 5.2', '>= 5.2.1'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
# Application Specific
# =================================================================
# background jobs
gem 'sidekiq', '~> 6.1', '>= 6.1.3'
# elasticsearch
gem 'elasticsearch-model', '~> 6.0'
gem 'elasticsearch-rails', '~> 6.0'
# authentication
gem 'devise', '~> 4.6', '>= 4.6.2'
gem 'omniauth', '~> 1.9'
gem 'omniauth-cas', '~> 1.1', '>= 1.1.1'
# Log all changes to models
gem "audited", "~> 4.9"
# metadata / library of congress specific
gem 'edtf', '~> 3.0', '>= 3.0.4'
# gem 'edtf-humanize', '~> 0.0.7'
# breadcrumbs
gem 'loaf'
# configruation
gem 'figaro'
# convert user strings to regex
gem 'to_regexp', '~> 0.2.1'
# files
gem 'mini_magick', '~> 4.11' # wrapper for imagemagick
gem 'rtesseract'
# used for batching jobs
gem 'sidekiq-batch'
# Development / Test Items (Primarily debugging)
# =====================================================================================
group :development, :test do
gem 'byebug', platforms: %i[mri mingw x64_mingw] # from rails new
gem 'factory_bot_rails'
gem 'faker'
gem 'pry'
gem 'pry-rails'
# Code critics
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rails'
end
group :test do
# test suite
gem 'capybara', '>= 2.15', '< 4.0'
gem 'database_cleaner'
gem 'rspec-html-matchers'
gem 'rspec-rails'
gem "rspec_junit_formatter"
gem 'shoulda'
gem 'shoulda-matchers'
# Codeclimate is not compatible with 0.18+. See https://github.com/codeclimate/test-reporter/issues/413
gem 'simplecov', '~> 0.17.1'
gem 'simplecov-console'
end
group :development do
gem 'annotate'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'web-console', '>= 3.3.0'
# performance helper
gem 'bullet' # helps to eliminate N+1 Queries
end
Run Code Online (Sandbox Code Playgroud)
ari*_*ver 12
我遇到过同样的问题。我想到了。删除我的coverage文件夹解决了我的问题。 (下次运行 SimpleCov 时它将再次创建。)
这就是解决问题的原因:
我之前安装了较新版本的 SimpleCov 来尝试分支覆盖(CodeClimate 尚不支持)。因此,当我切换回版本 1.17.1 以兼容 CodeClimate 时,该文件coverage/.last_run.json包含的 JSON 与 SimpleCov 1.17.1 的预期不匹配。因此,删除该文件(以及整个文件夹)允许 SimpleCov 1.17.1 以它理解的格式重新创建它。
我是这样想出来的:
我运行bundle open simplecov它在编辑器中打开了 gem 源代码。然后,我转到发生错误的行 (simplecov.rb:243),并添加一条puts语句以查看变量中的哈希值last_run。结果缺少covered_percent,而是包含分支覆盖信息,这是 1.17 版本不支持的。
| 归档时间: |
|
| 查看次数: |
1246 次 |
| 最近记录: |