Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add /app/views/* to coverage reports #345

Closed
onebree opened this issue Oct 31, 2014 · 8 comments
Closed

Unable to add /app/views/* to coverage reports #345

onebree opened this issue Oct 31, 2014 · 8 comments
Labels

Comments

@onebree
Copy link
Contributor

onebree commented Oct 31, 2014

Below is our spec_helper.rb file. I found how to add filters/groups on About.com. We decided to kill Spork when running the entire test suite, so coverage reports generate for each run. (We keep Spork on for testing individual pages, for speed's sake.)

We decided to use SimpleCov because its documentation says it reports on MVC, while (before I found the About article) it only reported M&C. After adding the group, The report yields 100% on Views. Lib, and Plugins (latter 2 I did not have before), with zero files listed.

Will adding Views to the coverage report raise our percentage? If so, how can I correctly include the directory? If not, what could I do to raise the %covered to a more realistic value?

52% covered
ruby 1.9.2
rails 3.1.10
simplecov 0.7.1

require 'simplecov'
require 'rubygems'
require 'spork'
require 'capybara/rspec'

Spork.prefork do
  unless ENV['DRB']
    require 'simplecov'
    SimpleCov.start 'rails' do
      add_group 'Views', '/app/views/*/'
      add_filter '/app/models/legacy/'
    end
  end

  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  Capybara.default_selector = :xpath
  Capybara.javascript_driver = :webkit

  RSpec.configure do |config|
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.use_transactional_fixtures = true
    config.infer_base_class_for_anonymous_controllers = false
    config.order = "random"
    config.include Helpers
  end

end

Spork.each_run do
  if ENV['DRB']
    require 'simplecov'
    SimpleCov.start 'rails'
  end

  class ActiveRecord::Base
    mattr_accessor :shared_connection
    @@shared_connection = nil

    def self.connection
      @@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
    end
  end
  ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

  User.acts_as_authentic { | c | c.maintain_sessions = false }

end
@bf4
Copy link
Collaborator

bf4 commented Oct 31, 2014

Does #340 help?

@onebree
Copy link
Contributor Author

onebree commented Nov 3, 2014

Thank you for the reply. #340 does help. I did comment on that post though with a couple clarifying questions.

@onebree
Copy link
Contributor Author

onebree commented Dec 9, 2014

@bf4 I commented again on #340 . I am still having an issue displaying Views in my coverage report. Does this mean that views are simply not executed during bundle exec rspec?

@bf4
Copy link
Collaborator

bf4 commented Dec 31, 2014

So, tl;dr SimpleCov will only report ruby files that are loaded (in your app) between when SimpleCov.start executes and the process ends. Adding a group only generates a new tab / presentation of the data.

Template files such as erb or haml aren't 'Ruby' files, or at least aren't loaded in a way that Coverage tracks them. After your SimpleCov.start try adding

SimpleCov.at_exit do
  puts Coverage.result.keys
end

Which will output every single file the Ruby stlib Coverage module recorded as being loaded. You'll likely notice your views aren't in that list.

@onebree
Copy link
Contributor Author

onebree commented Dec 31, 2014

Thank you for the reply. I have found a similar response elsewhere (StackOverflow), but wanted to wait until an official moderator of the repo responded.

@onebree onebree closed this as completed Dec 31, 2014
@bf4
Copy link
Collaborator

bf4 commented Jan 1, 2015

link?

@onebree
Copy link
Contributor Author

onebree commented Jan 2, 2015

This post links to others that I've seen as well...
http://stackoverflow.com/questions/21451540/how-do-i-get-coverage-for-views-in-rails

@bf4
Copy link
Collaborator

bf4 commented Jan 2, 2015

Ok, thanks. I should add some examples of this not working to the codebase :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants