Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

@paranishian

CircleCIからCodeClimateにテストカバレッジを送信する

CodeClimate導入してみたけどテストカバレッジが表示されない!なぜ!
とおもったら、ちゃんとそのための手順が必要でした。 :sweat_smile:

流れ

導入したプロジェクトはRuby on Railsだったので、テストカバレッジにはSimpleCovを採用してます。

rspecでSimpleCovが動いてる前提です。

rails_helper.rb
require 'simplecov'
SimpleCov.start
...

詳細はSimpleCovのREADME参照。

  1. CircleCIでrspec実行
  2. simplecovがcoverageを出力
  3. coverageをtest-reporterがCodeClimateにアップロード

CC_TEST_REPORTER_ID
Settings -> Test Coverage -> TEST REPORTER ID
から取得できます。

コード

CircleCIのconfigをdiffで表示するとこんな感じ。

.circleci/config.yml
version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.5.0-node-browsers
        environment:
+          CC_TEST_REPORTER_ID: 'XXXXXXXXXXXXXXX'
    working_directory: ~/my_project
    steps:
      - checkout

      ...

+      # Download test-reporter
+      - run:
+          name: Setup 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

      # Run rspec
      - run: |
+          ./cc-test-reporter before-build
          bundle exec rspec
+          ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?

      ...

以上です。

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
3
Help us understand the problem. What are the problem?