11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails SimpleCovでカバレッジが上書きされないようにする

11
Posted at

Rails SimpleCovでカバレッジが上書きされないようにする

RailsのテストのカバレッジにSimpleCovを使っています。

bundle exec rake test COVERAGE=trueを実行すると、ControllerやModelのテストが順番に実行されますが、coverage/index.htmlには一部の実行結果のみが残っていました。

具体的にはModelのテスト結果がControllerのテストで上書きされた状態です。

調べてみるとSimpleCov.command_nameをそれぞれ別の名前になるようにすればうまくマージされることがわかりました。

test_helper.rbに次のような設定を入れました。

test/test_helper.rb

:

require 'simplecov'
SimpleCov.start do
  add_filter "/test/"
  add_filter "/config/"

  SimpleCov.command_name "MiniTest #{Time.now}"

  add_group 'Controllers', 'app/controllers'
  add_group 'Models', 'app/models'
  add_group 'Helpers', 'app/helpers'
  add_group 'Libraries', 'lib'
end if ENV["COVERAGE"]

:

これで全てのテスト結果がマージされるようになりました。

参考:
http://stackoverflow.com/questions/15604390/minitest-with-simplecov

11
10
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
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?