8
votes

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?

1
Do you have a test that will return false for over?? That could explain the method being hit, but not all the results for that code being tested.Paul Fioravanti
Thanks @PaulFioravanti, I do have a negative test as well and it was run as part of this coverage session.Katherine Shimmins
Were you able to figure out what the problem was here? If so, please share! If not, would you be able to edit your question to include the full text of your spec ie where @entry is defined and what the subject of the test is.Paul Fioravanti
I'm having the same kind of problem. I'm using JRuby 1.7.1 in 1.9 mode, Rails 3.2.11 and the latest Simplecov version. Since I have the debug flag warning at every run I think it might be related. If you find a solution keep us informed please.Pierre Schambacher

1 Answers

1
votes

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.