Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get coverage for view specs with rspec, rails, and simplecov?

I have a project in which I'm using rails 3.2.3, rspec 2.9.0, and simplecov 0.6.1, all seem to be the latest gems.

I'm getting code coverage results for my controllers and models, but not my views. I've tried adding the group in my simplecov setup:

SimpleCov.start 'rails' do
  add_group 'Views', 'app/views'
end

And even explicitly saying I want .erb files included:

SimpleCov.start 'rails' do
  add_group 'Views', 'app/views/*/*.erb'
end

...but no dice. The "Views" group is there in my coverage results, but no files are listed there.

Has anyone gotten this working?

like image 974
dpassage Avatar asked Apr 06 '12 23:04

dpassage


People also ask

How is code coverage calculated?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

What is SimpleCov?

Test coverage using SimpleCov SimpleCov is a code coverage analysis tool for Ruby. It uses Ruby's built-in Coverage library to gather code coverage data. Add simplecov to your Gemfile and run bundle install: 1gem 'simplecov', require: false, group: :test.


1 Answers

Apparently, the answer to this is "you can't", due to a limitation in the standard ruby coverage library:

https://github.com/colszowka/simplecov/issues/38

like image 151
dpassage Avatar answered Oct 19 '22 10:10

dpassage