Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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 $?

      ...

以上です。

参考

paranishian
フリーランスのエンジニアです。がんばってます。
https://paranishian.hateblo.jp/
admin-guild
「Webサービスの運営に必要なあらゆる知見」を共有できる場として作られた、運営者のためのコミュニティです。
https://admin-guild.slack.com
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした