Skip to content

Models in subfolders are reporting 0% coverage  #671

Open
@darkcode85

Description

@darkcode85

Rails Version: 5.2.0.rc1
Simplecov Version: 0.15.1
Test Framework: Minitest

Test coverage are running properly for all the models in my application except for these that live in a sub folder, example:

I have a notification.rb model in app/models/notification.rb:

class Notification < ApplicationRecord
  belongs_to :user
end

And also a subclass model called email.rb in app/models/notification/email.rb:

class Notification::Email < Notification
   validates_presence_of :subject, :body
end

I have added the initial test coverage for both models. In test/models/notification_test.rb:

require 'test_helper'

class NotificationTest < ActiveSupport::TestCase
  should belong_to(:user)
end

and in test/models/notification/email_test.rb :

require 'test_helper'

class Notification::EmailTest < ActiveSupport::TestCase
  def setup
    @notification_email = build(:notification_email)
  end

  test 'should has a valid factory' do
    assert @notification_email.valid?
  end
end

Both tests are running and passing with success and I can force the test to fail but the coverage report always show 0% coverage for these models.

This is my test_helper.rb:

require 'simplecov'
SimpleCov.start :rails do
  add_filter 'app/models/application_record.rb'
  add_filter 'app/channels/application_cable/channel.rb'
  add_filter 'app/channels/application_cable/connection.rb'
end

ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'

class ActiveSupport::TestCase
  include FactoryBot::Syntax::Methods
end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions