Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: colszowka/simplecov
base: v0.5.2
...
head fork: colszowka/simplecov
compare: v0.5.3
Checking mergeability… Don't worry, you can still create the pull request.
  • 14 commits
  • 21 files changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 12, 2011
@colszowka Made test-project load libs dynamically
To allow dynamically adding source files in tests, the faked_project
now loads all source files dynamically. Updated expected results for All Files
groups in Cucumber features accordingly.
cea53d1
Commits on Sep 13, 2011
@colszowka Fixed encoding issues (closes #71)
The root cause was a weird char encoding in a authorship comment in
Rubygems' rubygems/package/tar_input.rb

Refactored the processing of skipped lines in simplecov to be more in line
with the other facilities in the library, specifically to use SimpleCov::SourceFile::Line
instead of raw source arrays.

Due to this, the processing of skipped lines in results only happens on the filtered
resultset, which won't include any gem/library files. This should also make result generation
faster.
2872cd2
@colszowka Added cucumber feature that verifies utf-8 compatibility in source files
(as a reaction to #71)
10653c2
@colszowka Added a cucumber feature that verifies nocov functionality
Also fixed a minor problem with it: #:nocov: worked, but # :nocov: did not, though it should have.
777c638
@colszowka Made nocov_token configurable, added cuke feature for that 67c40da
@colszowka Added instance method #status to SourceFile::Line for easy css class …
…evaluation
88ef4d8
@colszowka Adjusted html step definition to renamed css classes in html formatter 3b7df86
@colszowka Updated CHANGELOG 4424704
@colszowka Version bump to 0.5.3 82b2875
@colszowka Added note about favicon in html report to CHANGELOG f841ff2
@colszowka Added references to new screenshots on github pages to README fdb60e6
@colszowka Argh, RDoc syntax 0ce68b7
@colszowka Fiddling with README markup 7a1404e
@colszowka README tuning 602a26a
View
15 CHANGELOG.md
@@ -1,3 +1,18 @@
+v0.5.3 (2011-09-13)
+===================
+
+ * Fix for encoding issues that came from the nocov processing mechanism
+ (see https://github.com/colszowka/simplecov/issues/71)
+ * :nocov: lines are now actually being reflected in the HTML report and are marked in yellow.
+
+ * The Favicon in the HTML report is now determined by the overall coverage and will have the color
+ that the coverage percentage gets as a css class to immediately indicate coverage status on first sight.
+
+ * Introduced SimpleCov::SourceFile::Line#status method that returns the coverage status
+ as a string for this line - made SimpleCov::HTML use that.
+ * Refactored nocov processing and made it configurable using SimpleCov.ncov_token (or it's
+ alias SimpleCov.skip_token)
+
v0.5.2 (2011-09-12)
===================
View
14 README.rdoc
@@ -21,7 +21,7 @@ automatically when you launch SimpleCov. If you're curious, you can find it at h
Update your Gemfile with this and do a bundle install:
- gem 'simplecov', '>= 0.5.2', :require => false, :group => :test
+ gem 'simplecov', '>= 0.5.3', :require => false, :group => :test
Then, add the following to your test/test_helper.rb (right at the top, line 00) or spec_helper.rb or cucumber env.rb or whatever
test framework you prefer, really - just make sure simplecov is loaded and started BEFORE your app code is loaded:
@@ -39,17 +39,19 @@ for it which will give you handy tabs in the output webpage for your Controllers
== Example output
-For the Devise Ruby gem (some tests were removed, they just have too awesome test coverage...)
+<b>Coverage results report, fully browsable locally with sorting and much more:</b>
+http://colszowka.github.com/simplecov/devise_result-0.5.3.png
-http://img.skitch.com/20100823-n9f52i3ty3qa7cqj33rafghrtc.png
+<b>Source file coverage details view:</b>
+http://colszowka.github.com/simplecov/devise_source_file-0.5.3.png
-== Usage with Cucumber, RSpec, (name your framework)
+== Use it with any framework!
Similarily to the usage with Test::Unit described above, the only thing you have to do is to add the simplecov
config to the very top of your Cucumber/RSpec/whatever setup file.
-Just add the setup snippet at the very(!) top of features/support/env.rb (for Cucumber) or spec/spec_helper.rb (for RSpec).
-Other test frameworks should work accordingly.
+Add the setup code to the <b>top</b> of +features/support/env.rb+ (for Cucumber) or +spec/spec_helper.rb+ (for RSpec).
+Other test frameworks should work accordingly, whatever their setup file may be:
require 'simplecov'
SimpleCov.start 'rails'
View
2  features/config_autoload.feature
@@ -36,7 +36,7 @@ Feature:
And I should see the groups:
| name | coverage | files |
- | All Files | 90.7% | 4 |
+ | All Files | 90.48% | 4 |
And I should see the source files:
| name | coverage |
View
79 features/config_nocov_token.feature
@@ -0,0 +1,79 @@
+@test_unit @nocov
+Feature:
+
+ Code wrapped in # :nocov: will be ignored by coverage reports.
+ The name of the token can be configured with SimpleCov.nocov_token or SimpleCov.skip_token
+
+ Scenario: Custom nocov token using nocov_token
+ Given SimpleCov for Test/Unit is configured with:
+ """
+ require 'simplecov'
+ SimpleCov.start 'test_frameworks' do
+ nocov_token 'skippit'
+ end
+ """
+
+ Given a file named "lib/faked_project/nocov.rb" with:
+ """
+ class SourceCodeWithNocov
+ # :skippit:
+ def some_weird_code
+ never_reached
+ rescue => err
+ but no one cares about invalid ruby here
+ end
+ # :skippit:
+ end
+ """
+
+ When I open the coverage report generated with `bundle exec rake test`
+
+ Then I should see the source files:
+ | name | coverage |
+ | lib/faked_project.rb | 100.0 % |
+ | lib/faked_project/some_class.rb | 80.0 % |
+ | lib/faked_project/framework_specific.rb | 75.0 % |
+ | lib/faked_project/meta_magic.rb | 100.0 % |
+ | lib/faked_project/nocov.rb | 100.0 % |
+
+ And there should be 5 skipped lines in the source files
+
+ And the report should be based upon:
+ | Unit Tests |
+
+ Scenario: Custom nocov token using skip_token
+ Given SimpleCov for Test/Unit is configured with:
+ """
+ require 'simplecov'
+ SimpleCov.start 'test_frameworks' do
+ skip_token 'skippit'
+ end
+ """
+
+ Given a file named "lib/faked_project/nocov.rb" with:
+ """
+ class SourceCodeWithNocov
+ # :skippit:
+ def some_weird_code
+ never_reached
+ rescue => err
+ but no one cares about invalid ruby here
+ end
+ # :skippit:
+ end
+ """
+
+ When I open the coverage report generated with `bundle exec rake test`
+
+ Then I should see the source files:
+ | name | coverage |
+ | lib/faked_project.rb | 100.0 % |
+ | lib/faked_project/some_class.rb | 80.0 % |
+ | lib/faked_project/framework_specific.rb | 75.0 % |
+ | lib/faked_project/meta_magic.rb | 100.0 % |
+ | lib/faked_project/nocov.rb | 100.0 % |
+
+ And there should be 5 skipped lines in the source files
+
+ And the report should be based upon:
+ | Unit Tests |
View
2  features/cucumber_basic.feature
@@ -14,7 +14,7 @@ Feature:
When I open the coverage report generated with `bundle exec cucumber features`
Then I should see the groups:
| name | coverage | files |
- | All Files | 91.38% | 6 |
+ | All Files | 91.23% | 6 |
And I should see the source files:
| name | coverage |
View
2  features/merging_test_unit_and_rspec.feature
@@ -34,7 +34,7 @@ Feature:
And I should see the groups:
| name | coverage | files |
- | All Files | 90.7% | 4 |
+ | All Files | 90.48% | 4 |
And I should see the source files:
| name | coverage |
View
2  features/rspec_basic.feature
@@ -14,7 +14,7 @@ Feature:
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
- | All Files | 90.91% | 6 |
+ | All Files | 90.74% | 6 |
And I should see the source files:
| name | coverage |
View
2  features/rspec_groups_and_filters_basic.feature
@@ -17,7 +17,7 @@ Feature:
When I open the coverage report generated with `bundle exec rspec spec`
And I should see the groups:
| name | coverage | files |
- | All Files | 88.37% | 4 |
+ | All Files | 88.1% | 4 |
| Libs | 86.11% | 3 |
| Ungrouped | 100.0% | 1 |
View
70 features/skipping_code_blocks_manually.feature
@@ -0,0 +1,70 @@
+@test_unit @nocov
+Feature:
+
+ When code is wrapped in :nocov: comment blocks, it does not count
+ against the coverage numbers.
+
+ Background:
+ Given SimpleCov for Test/Unit is configured with:
+ """
+ require 'simplecov'
+ SimpleCov.start 'test_frameworks'
+ """
+
+ Scenario: Plain run with a nocov'd method
+ Given a file named "lib/faked_project/nocov.rb" with:
+ """
+ class SourceCodeWithNocov
+ #:nocov:
+ def some_weird_code
+ never_reached
+ rescue => err
+ but no one cares about invalid ruby here
+ end
+ #:nocov:
+ end
+ """
+
+ When I open the coverage report generated with `bundle exec rake test`
+
+ Then I should see the source files:
+ | name | coverage |
+ | lib/faked_project.rb | 100.0 % |
+ | lib/faked_project/some_class.rb | 80.0 % |
+ | lib/faked_project/framework_specific.rb | 75.0 % |
+ | lib/faked_project/meta_magic.rb | 100.0 % |
+ | lib/faked_project/nocov.rb | 100.0 % |
+
+ And there should be 5 skipped lines in the source files
+
+ And the report should be based upon:
+ | Unit Tests |
+
+ Scenario: Number of spaces should not mix up nocov results
+ Given a file named "lib/faked_project/nocov.rb" with:
+ """
+ class SourceCodeWithNocov
+ # :nocov:
+ def some_weird_code
+ never_reached
+ rescue => err
+ but no one cares about invalid ruby here
+ end
+ # :nocov:
+ end
+ """
+
+ When I open the coverage report generated with `bundle exec rake test`
+
+ Then I should see the source files:
+ | name | coverage |
+ | lib/faked_project.rb | 100.0 % |
+ | lib/faked_project/some_class.rb | 80.0 % |
+ | lib/faked_project/framework_specific.rb | 75.0 % |
+ | lib/faked_project/meta_magic.rb | 100.0 % |
+ | lib/faked_project/nocov.rb | 100.0 % |
+
+ And there should be 5 skipped lines in the source files
+
+ And the report should be based upon:
+ | Unit Tests |
View
3  features/step_definitions/html_steps.rb
@@ -40,3 +40,6 @@ def available_source_files
files.sort_by {|hsh| hsh["name"] }.should == expected_files.sort_by {|hsh| hsh["name"] }
end
+Then /^there should be (\d+) skipped lines in the source files$/ do |expected_count|
+ all(".source_table ol li.skipped").count.should == expected_count.to_i
+end
View
2  features/test_unit_basic.feature
@@ -14,7 +14,7 @@ Feature:
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
- | All Files | 91.53% | 6 |
+ | All Files | 91.38% | 6 |
And I should see the source files:
| name | coverage |
View
2  features/test_unit_groups_and_filters_basic.feature
@@ -17,7 +17,7 @@ Feature:
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
- | All Files | 88.37% | 4 |
+ | All Files | 88.1% | 4 |
| Libs | 86.11% | 3 |
| Ungrouped | 100.0% | 1 |
View
67 features/unicode_compatiblity.feature
@@ -0,0 +1,67 @@
+@test_unit @unicode
+Feature:
+
+ Files with unicode in their source should be no problem at all for
+ generating a proper coverage report.
+
+ Background:
+ Given SimpleCov for Test/Unit is configured with:
+ """
+ require 'simplecov'
+ SimpleCov.start 'test_frameworks'
+ """
+
+ Scenario: Snowman inside method string
+ Given a file named "lib/faked_project/unicode.rb" with:
+ """
+ # encoding: UTF-8
+ class SourceCodeWithUnicode
+ def self.yell!
+ puts "☃"
+ end
+ end
+ """
+
+ When I open the coverage report generated with `bundle exec rake test`
+ Then I should see the groups:
+ | name | coverage | files |
+ | All Files | 86.67% | 5 |
+
+ And I should see the source files:
+ | name | coverage |
+ | lib/faked_project.rb | 100.0 % |
+ | lib/faked_project/some_class.rb | 80.0 % |
+ | lib/faked_project/framework_specific.rb | 75.0 % |
+ | lib/faked_project/meta_magic.rb | 100.0 % |
+ | lib/faked_project/unicode.rb | 66.67 % |
+
+ And the report should be based upon:
+ | Unit Tests |
+
+ Scenario: Author name in comment
+ Given a file named "lib/faked_project/unicode.rb" with:
+ """
+ # encoding: UTF-8
+ # author: Javiér Hernández
+ class SomeClassWrittenByAForeigner
+ def self.yell!
+ foo
+ end
+ end
+ """
+
+ When I open the coverage report generated with `bundle exec rake test`
+ Then I should see the groups:
+ | name | coverage | files |
+ | All Files | 86.67% | 5 |
+
+ And I should see the source files:
+ | name | coverage |
+ | lib/faked_project.rb | 100.0 % |
+ | lib/faked_project/some_class.rb | 80.0 % |
+ | lib/faked_project/framework_specific.rb | 75.0 % |
+ | lib/faked_project/meta_magic.rb | 100.0 % |
+ | lib/faked_project/unicode.rb | 66.67 % |
+
+ And the report should be based upon:
+ | Unit Tests |
View
13 lib/simplecov/configuration.rb
@@ -72,6 +72,19 @@ def formatter(formatter=nil)
raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter
@formatter
end
+
+ #
+ # Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from
+ # the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token
+ # can be configured to be any other string using this.
+ #
+ # Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip')
+ #
+ def nocov_token(nocov_token=nil)
+ return @nocov_token if @nocov_token and nocov_token.nil?
+ @nocov_token = (nocov_token || 'nocov')
+ end
+ alias_method :skip_token, :nocov_token
#
# Returns the configured groups. Add groups using SimpleCov.add_group
View
40 lib/simplecov/source_file.rb
@@ -24,11 +24,12 @@ class Line
alias_method :line, :line_number
alias_method :number, :line_number
- def initialize(src, line_number, coverage, skipped = false)
+ def initialize(src, line_number, coverage)
raise ArgumentError, "Only String accepted for source" unless src.kind_of?(String)
raise ArgumentError, "Only Fixnum accepted for line_number" unless line_number.kind_of?(Fixnum)
raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil?
- @src, @line_number, @coverage, @skipped = src, line_number, coverage, skipped
+ @src, @line_number, @coverage = src, line_number, coverage
+ @skipped = false
end
# Returns true if this is a line that should have been covered, but was not
@@ -45,9 +46,25 @@ def covered?
def never?
not skipped? and coverage.nil?
end
+
+ # Flags this line as skipped
+ def skipped!
+ @skipped = true
+ end
+ # Returns true if this line was skipped, false otherwise. Lines are skipped if they are wrapped with
+ # # :nocov: comment lines.
def skipped?
- @skipped
+ !!skipped
+ end
+
+ # The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use
+ # as a css class in report generation
+ def status
+ return 'skipped' if skipped?
+ return 'never' if never?
+ return 'missed' if missed?
+ return 'covered' if covered?
end
end
@@ -61,7 +78,6 @@ def skipped?
def initialize(filename, coverage)
@filename, @coverage, @src = filename, coverage, File.readlines(filename)
- @skipped_line_numbers = process_skipped_lines
end
# Returns all source lines for this file as instances of SimpleCov::SourceFile::Line,
@@ -77,8 +93,9 @@ def lines
# Initialize lines
@lines = []
src.each_with_index do |src, i|
- @lines << SimpleCov::SourceFile::Line.new(src, i+1, coverage[i], @skipped_line_numbers.include?(i + 1))
+ @lines << SimpleCov::SourceFile::Line.new(src, i+1, coverage[i])
end
+ process_skipped_lines!
@lines
end
alias_method :source_lines, :lines
@@ -94,7 +111,6 @@ def covered_percent
(covered_lines.count) * 100 / (lines.count - never_lines.count - skipped_lines.count).to_f
end
- #
def covered_strength
return 0 if lines.length == 0 or lines.length == never_lines.count
lines_strength = 0
@@ -133,17 +149,17 @@ def lines_of_code
covered_lines.count + missed_lines.count
end
- def process_skipped_lines
- skipped_line_numbers = []
+ # Will go through all source files and mark lines that are wrapped within # :nocov: comment blocks
+ # as skipped.
+ def process_skipped_lines!
skipping = false
- @src.each_with_index do |line, i|
- if line =~ /^\s*#\:nocov\:/
+ lines.each do |line|
+ if line.src =~ /^([\s]*)#([\s]*)(\:#{SimpleCov.nocov_token}\:)/
skipping = !skipping
else
- skipped_line_numbers << i + 1 if skipping
+ line.skipped! if skipping
end
end
- skipped_line_numbers
end
private
View
2  lib/simplecov/version.rb
@@ -1,3 +1,3 @@
module SimpleCov
- VERSION = "0.5.2"
+ VERSION = "0.5.3"
end
View
2  simplecov.gemspec
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
gem.summary = gem.description
gem.add_dependency 'multi_json', '~> 1.0.3'
- gem.add_dependency 'simplecov-html', '~> 0.5.0'
+ gem.add_dependency 'simplecov-html', '~> 0.5.3'
gem.add_development_dependency 'aruba', '~> 0.4'
gem.add_development_dependency 'capybara', '~> 1.0'
gem.add_development_dependency 'cucumber', '~> 1.0'
View
8 test/faked_project/lib/faked_project.rb
@@ -4,8 +4,8 @@ def self.foo
end
end
-require 'faked_project/some_class'
-require 'faked_project/meta_magic'
-require 'faked_project/framework_specific'
+Dir[File.join(File.dirname(__FILE__), 'faked_project/*.rb')].each do |file|
+ require file # Require all source files in project dynamically so we can inject some stuff depending on test situation
+end
-FakedProject.send :include, MetaMagic
+FakedProject.send :include, MetaMagic
View
1  test/helper.rb
@@ -13,6 +13,7 @@ def source_fixture(filename)
# Keep 1.8-rubies from complaining about missing tests in each file that covers only 1.9 functionality
def default_test
end
+
end
require 'shoulda_macros'
View
18 test/shoulda_macros.rb
@@ -8,4 +8,22 @@ def on_ruby(*ruby_versions)
yield
end if ruby_versions.any? {|v| RUBY_VERSION =~ /#{v}/ }
end
+
+ def should_be(boolean_flag)
+ should "be #{boolean_flag}" do
+ assert_equal true, subject.send(boolean_flag)
+ end
+ end
+
+ def should_not_be(boolean_flag)
+ should "not be #{boolean_flag}" do
+ assert_equal false, subject.send(boolean_flag)
+ end
+ end
+
+ def should_have(attr_name, expectation)
+ should "have #{attr_name} == #{expectation.inspect}" do
+ assert_equal expectation, subject.send(attr_name)
+ end
+ end
end
View
66 test/test_source_file_line.rb
@@ -1,11 +1,14 @@
require 'helper'
class TestSourceFileLine < Test::Unit::TestCase
+
+
on_ruby '1.9' do
context "A source line" do
setup do
@line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 3)
end
+ subject { @line }
should 'return "# the ruby source" as src' do
assert_equal '# the ruby source', @line.src
@@ -23,72 +26,67 @@ class TestSourceFileLine < Test::Unit::TestCase
assert_equal @line.line_number, @line.line
assert_equal @line.line_number, @line.number
end
+
+ context "flagged as skipped!" do
+ setup { @line.skipped! }
+
+ should_not_be :covered?
+ should_be :skipped?
+ should_not_be :missed?
+ should_not_be :never?
+ should_have :status, 'skipped'
+ end
end
-
+
context "A source line with coverage" do
setup do
@line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 3)
end
+ subject { @line }
should "have coverage of 3" do
assert_equal 3, @line.coverage
end
- should "be covered?" do
- assert @line.covered?
- end
-
- should "not be never?" do
- assert !@line.never?
- end
-
- should "not be missed?" do
- assert !@line.missed?
- end
+ should_be :covered?
+ should_not_be :skipped?
+ should_not_be :missed?
+ should_not_be :never?
+ should_have :status, 'covered'
end
context "A source line without coverage" do
setup do
@line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 0)
end
+ subject { @line }
should "have coverage of 0" do
assert_equal 0, @line.coverage
end
- should "not be covered?" do
- assert !@line.covered?
- end
-
- should "not be never?" do
- assert !@line.never?
- end
-
- should "be missed?" do
- assert @line.missed?
- end
+ should_not_be :covered?
+ should_not_be :skipped?
+ should_be :missed?
+ should_not_be :never?
+ should_have :status, 'missed'
end
context "A source line with no code" do
setup do
@line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, nil)
end
+ subject { @line }
should "have nil coverage" do
assert_nil @line.coverage
end
- should "not be covered?" do
- assert !@line.covered?
- end
-
- should "be never?" do
- assert @line.never?
- end
-
- should "not be missed?" do
- assert !@line.missed?
- end
+ should_not_be :covered?
+ should_not_be :skipped?
+ should_not_be :missed?
+ should_be :never?
+ should_have :status, 'never'
end
should "raise ArgumentError when initialized with invalid src" do

No commit comments for this range

Something went wrong with that request. Please try again.