Skip to content

Commit

Permalink
Made nocov_token configurable, added cuke feature for that
Browse files Browse the repository at this point in the history
  • Loading branch information
colszowka committed Sep 13, 2011
1 parent 777c638 commit 67c40da
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
79 changes: 79 additions & 0 deletions 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 |
2 changes: 1 addition & 1 deletion features/skipping_code_blocks_manually.feature
Expand Up @@ -11,7 +11,7 @@ Feature:
SimpleCov.start 'test_frameworks'
"""

Scenario:
Scenario: Plain run with a nocov'd method
Given a file named "lib/faked_project/nocov.rb" with:
"""
class SourceCodeWithNocov
Expand Down
13 changes: 13 additions & 0 deletions lib/simplecov/configuration.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/source_file.rb
Expand Up @@ -145,7 +145,7 @@ def lines_of_code
def process_skipped_lines!
skipping = false
lines.each do |line|
if line.src =~ /^([\s]*)#([\s]*)(\:nocov\:)/
if line.src =~ /^([\s]*)#([\s]*)(\:#{SimpleCov.nocov_token}\:)/
skipping = !skipping
else
line.skipped! if skipping
Expand Down

0 comments on commit 67c40da

Please sign in to comment.