LoginSignup
0
0

More than 5 years have passed since last update.

rubocopのエラーをCircleCIのTestSummaryに表示する

Last updated at Posted at 2019-04-27

目的

タイトル通りですが、CircleCIでrubocopがこけた時TestSummaryにいい感じに表示して下までスクロールしなくても結果を見られるようにします。

というのがあったのですが、既にreadonlyになっていて試してみたけど動きませんでした。これを参考に作ろうかな?と思ったけど、rspecでrubocopやっちゃったら?みたいな話を見かけてそっちの方が手っ取り早そうだったので試してみました。

rspceでrubocopを動かす

どこでもいいですけど上記記事を真似してspec/lint/rubocop_spec.rbに作りました。

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'bundle exec rubocop', rubocop: true do
  it '違反はないはず' do
    @report = `bundle exec rubocop --config .rubocop.yml`
    expect(@report.match('Offenses')).to be_nil, "Rubocop offenses found.\n#{@report}"
  end
end

rubocop: trueとタグをつけてるのはCircleCI上で動かすときrspecとは別に動かしたかったからです。タグをつけておくと除外して実行可能です。

circleci/config.yml

関係ないところははしょります。

    - run:
        name: rubocop
        command: |
          mkdir /tmp/test-results

          bundle exec rspec  \
            --format progress \
            --format RspecJunitFormatter \
            --out /tmp/test-results/rubocop.xml \
            spec/lint/rubocop_spec.rb

    - run:
        name: rspec
        command: |
          bundle exec rspec \
            --format progress \
            --format RspecJunitFormatter \
            --out /tmp/test-results/rspec.xml \
            --tag ~rubocop

    # collect reports
    - store_test_results:
        path: /tmp/test-results
    - store_artifacts:
        path: /tmp/test-results
        destination: test-results

ちょっと強引ですが目的は達成できました。

rubocop --tag ~rubocop~をつけると除外できるようです。

ローカルでrpsecを実行したときいちいちタグをつけないとrubocopのやつも動いてしまうのがちょっと微妙ですが、circleciつかってると余り全部のテストをローカルで動かすこともないですよね?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0