目的
タイトル通りですが、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つかってると余り全部のテストをローカルで動かすこともないですよね?