Skip to content

Coverage reports wrong number of lines #1196

@donv

Description

@donv

Given the file my_model.rb:

class MyModel
  class_eval <<-EOT, __FILE__, __LINE__
    def a
      foo
    end

    def b
      bar
    end
  EOT
end

and the following code to measure coverage in coverage_example.rb:

file = File.expand_path('my_model.rb', File.dirname(__FILE__))
puts File.read(file).split("\n").size
require 'coverage'
Coverage.start
require file.chomp('.rb')
puts Coverage.result[file].size

Run with jruby 1.7.6 and debug enabled, the output is:

$ jruby --debug coverage_example.rb 
11
15
$ 

I would expect the numbers to be the same, possibly the last to be smaller than the first.

The discrepancy trigger very noisy warning messages when measuring coverage, for example using simplecov.

What could cause the difference?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions