Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cope with Rcov giving different lines for coverage with Ruby 1.8 and 1.9

  • Loading branch information...
commit 9b33a30640aa7ac25d516a1d752381c45e454f6e 1 parent 79b0104
@josephwilk josephwilk authored
View
3  cucumber.yml
@@ -0,0 +1,3 @@
+default: --profile 1_8
+1_8: --tags ~@ruby_1_9
+1_9: --tags @ruby_1_9
View
37 features/coverage_of.feature
@@ -6,6 +6,7 @@ Feature: Coverage Of
Background:
Given I am using the simple example app
+ @ruby_1_8
Scenario: Get coverage of a source file that's partly touched by the feature that was run
Given I have run cucover -- features/call_foo.feature
When I run cucover --coverage-of lib/foo.rb
@@ -23,6 +24,7 @@ Feature: Coverage Of
"""
+ @ruby_1_8
Scenario: Run another feature that also covers the same source file
Given I have run cucover -- features/call_foo.feature
And I have run cucover -- features/call_foo_and_bar_together.feature
@@ -41,4 +43,39 @@ Feature: Coverage Of
"""
+ @ruby_1_9
+ Scenario: Get coverage of a source file that's partly touched by the feature that was run
+ Given I have run cucover -- features/call_foo.feature
+ When I run cucover --coverage-of lib/foo.rb
+ Then it should pass with:
+ """
+ 1 class Foo
+ 2 def execute features/call_foo.feature:3
+ 3 true features/call_foo.feature:3
+ 4 end features/call_foo.feature:3
+ 5
+ 6 def sloppy_me..
+ 7 1/0
+ 8 end
+ 9 end
+
+ """
+ @ruby_1_9
+ Scenario: Run another feature that also covers the same source file
+ Given I have run cucover -- features/call_foo.feature
+ And I have run cucover -- features/call_foo_and_bar_together.feature
+ When I run cucover --coverage-of lib/foo.rb
+ Then it should pass with:
+ """
+ 1 class Foo
+ 2 def execute features/call_foo.feature:3, features/call_foo_and_bar_together.feature:3
+ 3 true features/call_foo.feature:3, features/call_foo_and_bar_together.feature:3
+ 4 end features/call_foo.feature:3, features/call_foo_and_bar_together.feature:3
+ 5
+ 6 def sloppy_me..
+ 7 1/0
+ 8 end
+ 9 end
+
+ """
View
20 lib/cucover.rb
@@ -1,4 +1,4 @@
-$:.unshift(File.dirname(__FILE__))
+$:.unshift(File.dirname(__FILE__))
require 'dependencies'
require 'cucover/logging_config'
require 'cucover/cli_commands/coverage_of'
@@ -12,6 +12,8 @@
require 'cucover/recording'
require 'cucover/recorder'
require 'cucover/store'
+require 'cucover/line_numbers'
+
require 'at_exit_hook'
@@ -20,11 +22,11 @@ class << self
def logger
Logging::Logger['Cucover']
end
-
+
def should_execute?(scenario_or_table_row)
controller(scenario_or_table_row).should_execute?
end
-
+
def start_recording!(scenario_or_table_row)
raise("Already recording. Please call stop first.") if recording?
@@ -40,24 +42,24 @@ def stop_recording!
store.keep!(@current_recorder.recording)
@current_recorder = nil
end
-
+
def record_file(source_file)
Cucover.logger.debug("Recording extra source file #{source_file}")
@current_recorder.record_file!(source_file)
end
-
+
private
-
+
def controller(scenario_or_table_row)
Controller.new(scenario_or_table_row.file_colon_line, store)
end
-
+
def recording?
!!@current_recorder
end
-
+
def store
@store ||= Store.new
end
- end
+ end
end
View
10 lib/cucover/line_numbers.rb
@@ -0,0 +1,10 @@
+require 'rbconfig'
+
+module Cucover
+ module LineNumbers
+ # Different Ruby versions have slightly different line numbers with rcov
+ def self.offset
+ Config::CONFIG['MINOR'] == '9' ? 0 : 1
+ end
+ end
+end
View
24 lib/cucover/recording/covered_file.rb
@@ -1,16 +1,16 @@
module Cucover
class Recording::CoveredFile
attr_reader :file
-
+
def initialize(full_filename, rcov_marked_info, recording)
@full_filename = full_filename
@rcov_marked_info = rcov_marked_info
@recording = recording
@file = File.expand_path(full_filename).gsub(/^#{Dir.pwd}\//, '')
-
+
extend HasLineNumberDetail if @rcov_marked_info
end
-
+
def dirty?
Cucover.logger.debug("#{file} last modified at #{File.mtime(@full_filename)}")
Cucover.logger.debug("#{file} recording started at #{@recording.start_time}")
@@ -18,36 +18,36 @@ def dirty?
Cucover.logger.debug("verdict: #{(result ? "dirty" : "not dirty")}")
result
end
-
+
def covers_line?(line_number)
covered_lines.include?(line_number)
end
-
+
def ==(other)
other == file
end
-
+
def to_s
"#{file}:#{covered_lines.join(':')}"
end
-
+
private
-
+
def covered_lines
['<unknown lines>']
end
-
+
module HasLineNumberDetail
def covered_lines
return @covered_lines if @covered_lines
-
+
@covered_lines = []
@rcov_marked_info.each_with_index do |covered, index|
- line_number = index + 1
+ line_number = index + Cucover::LineNumbers.offset
@covered_lines << line_number if covered
end
@covered_lines
end
end
end
-end
+end
View
4 lib/dependencies.rb
@@ -1,10 +1,10 @@
require 'rubygems'
-gem 'logging', '>= 1.1.4'
+gem 'logging', '>= 1.4.1'
require 'logging'
gem 'cucumber', '>= 0.3.1'
require 'cucumber'
-gem 'relevance-rcov','>= 0.8.3.4'
+gem 'rcov', '>= 0.9.8'
require 'rcov'
Please sign in to comment.
Something went wrong with that request. Please try again.