Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplecov coverage report seems to miss certain lines

Just after some clarification on how simplecov determines if a line has been exercised by a test.

I have the following method:

def over?
  end_at < Time.zone.now
end

in which end_at is an ActiveRecord attribute on the object.

Which is exercised in the following spec:

describe CalendarEntry do
  it 'can determine that an event has ended' do
    @entry.end_at = 1.day.ago
    @entry.over?.should be_true
  end
end

After running the spec with coverage, it shows the following result:

coverage report

I've run the test in debug mode with a break point on this line and confirmed that the spec is indeed hitting it.

This isn't isolated to just this line in this method, every line that includes the use of an ActiveRecord associated getter is shown as not covered. Could be coincidence, but seems a bit odd.

Environment: ruby 1.9.3-p327 (mri), rails 3.2.8, simplecov 0.7.1, rspec 2.10.0.

Any ideas on why simplecov thinks it's not covered?

like image 613
Katherine Shimmins Avatar asked Dec 15 '12 05:12

Katherine Shimmins


1 Answers

OK so I add the same kind of problem with JRuby running on Windows. The answer was actually prompted to me, Simplecov can miss some lines if not runned in debug mode.

(j)ruby --debug -S rspec spec

With the --debug option it did worked and I was back to 100% coverage as expected.

like image 55
Pierre Schambacher Avatar answered Sep 17 '22 13:09

Pierre Schambacher