使用Simplecov运行现有TestUnit测试和覆盖的RSpec

时间:2012-09-03 07:30:29

标签: ruby-on-rails rspec code-coverage testunit

我是ROR的新手,想知道Simplecov是否在同一个项目中为TestUnit和RSpec测试提供测试覆盖率?

我正在将我们在RSpec中编写的一些测试从独立的webapp迁移到当前使用TestUnit的现有webapp。

我知道RSpec和TestUnit都可以存在于同一个项目中,但我还没有看到Simplecov如何为两个测试框架生成覆盖范围。

当我运行命令行bundle exec rake spec时,我得到:

Coverage report generated for RSpec to /.../coverage. 0 / 0 LOC (0.0%) covered.

当我运行bundle exec rake test时,我会生成测试覆盖率。

计划是将所有内容从TestUnit迁移到rspec,但是我们希望在迁移到TestUnit时,我们希望在Simplecov中同时进行400多项TestUnit和RSpec测试。

我确定我的配置中必定存在不正确的内容

非常感谢任何帮助!

我有以下设置:

--- Rakefile ---

require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'simplecov'

if Rails.env == 'test' || Rails.env == 'development'
  require 'ci/reporter/rake/test_unit'
  require 'ci/reporter/rake/rspec'
end

SimpleCov.start 'rails' do
  add_filter "/test/"
  add_filter "/spec/"
end

- spec / spec_helper.rb -

ENV["RAILS_ENV"] ||= 'test'

require 'simplecov'
SimpleCov.start 'rails'

require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

- test / test_helper.rb -

require 'simplecov'
SimpleCov.start 'rails' do
  add_filter "/vendor/"
end

ENV["RAILS_ENV"] = "test"

require File.expand_path('../../config/environment', __FILE__)

1 个答案:

答案 0 :(得分:0)

这不直接回答你的问题,但是如果它有帮助,我有一个bash脚本,为你从TestUnit移植到RSpec做了很多工作。它在https://github.com/Noreaster76/porter。您可以使用它来转换TestUnit文件,在稍微清理一下结果之后,您就不会遇到必须同时运行RSpec和TestUnit的问题。

相关问题