simplecov 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -7
  2. data/.gitignore +0 -1
  3. data/.rubocop.yml +69 -0
  4. data/CHANGELOG.md +39 -22
  5. data/Gemfile +16 -15
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +183 -178
  8. data/Rakefile +16 -7
  9. data/doc/alternate-formatters.md +36 -0
  10. data/doc/commercial-services.md +20 -0
  11. data/doc/editor-integration.md +13 -0
  12. data/features/rspec_basic.feature +3 -2
  13. data/features/rspec_groups_and_filters_complex.feature +2 -0
  14. data/features/rspec_groups_using_filter_class.feature +3 -2
  15. data/features/step_definitions/html_steps.rb +6 -7
  16. data/features/step_definitions/simplecov_steps.rb +18 -16
  17. data/features/step_definitions/transformers.rb +2 -2
  18. data/features/step_definitions/web_steps.rb +4 -4
  19. data/features/support/env.rb +17 -15
  20. data/lib/simplecov.rb +35 -24
  21. data/lib/simplecov/command_guesser.rb +33 -34
  22. data/lib/simplecov/configuration.rb +238 -234
  23. data/lib/simplecov/defaults.rb +37 -36
  24. data/lib/simplecov/exit_codes.rb +7 -5
  25. data/lib/simplecov/file_list.rb +38 -36
  26. data/lib/simplecov/filter.rb +12 -2
  27. data/lib/simplecov/formatter.rb +2 -2
  28. data/lib/simplecov/formatter/simple_formatter.rb +1 -1
  29. data/lib/simplecov/jruby_fix.rb +4 -4
  30. data/lib/simplecov/last_run.rb +15 -13
  31. data/lib/simplecov/merge_helpers.rb +26 -27
  32. data/lib/simplecov/no_defaults.rb +2 -2
  33. data/lib/simplecov/profiles.rb +21 -19
  34. data/lib/simplecov/railtie.rb +1 -1
  35. data/lib/simplecov/railties/tasks.rake +7 -7
  36. data/lib/simplecov/result.rb +5 -5
  37. data/lib/simplecov/result_merger.rb +65 -62
  38. data/lib/simplecov/source_file.rb +23 -24
  39. data/lib/simplecov/version.rb +20 -1
  40. data/simplecov.gemspec +14 -12
  41. data/test/faked_project/Gemfile +5 -5
  42. data/test/faked_project/Rakefile +4 -4
  43. data/test/faked_project/features/step_definitions/my_steps.rb +3 -4
  44. data/test/faked_project/features/support/env.rb +5 -5
  45. data/test/faked_project/lib/faked_project.rb +1 -1
  46. data/test/faked_project/lib/faked_project/some_class.rb +3 -4
  47. data/test/faked_project/spec/faked_spec.rb +2 -2
  48. data/test/faked_project/spec/forking_spec.rb +7 -0
  49. data/test/faked_project/spec/meta_magic_spec.rb +1 -1
  50. data/test/faked_project/spec/some_class_spec.rb +3 -3
  51. data/test/faked_project/spec/spec_helper.rb +4 -8
  52. data/test/faked_project/test/faked_test.rb +2 -2
  53. data/test/faked_project/test/meta_magic_test.rb +1 -1
  54. data/test/faked_project/test/some_class_test.rb +3 -3
  55. data/test/faked_project/test/test_helper.rb +5 -9
  56. data/test/fixtures/app/controllers/sample_controller.rb +1 -1
  57. data/test/fixtures/app/models/user.rb +1 -1
  58. data/test/fixtures/deleted_source_sample.rb +3 -3
  59. data/test/fixtures/frameworks/rspec_bad.rb +4 -4
  60. data/test/fixtures/frameworks/rspec_good.rb +4 -4
  61. data/test/fixtures/frameworks/testunit_bad.rb +3 -3
  62. data/test/fixtures/frameworks/testunit_good.rb +3 -3
  63. data/test/fixtures/resultset2.rb +0 -1
  64. data/test/fixtures/sample.rb +1 -1
  65. data/test/fixtures/utf-8.rb +1 -1
  66. data/test/helper.rb +8 -8
  67. data/test/test_1_8_fallbacks.rb +6 -6
  68. data/test/test_command_guesser.rb +7 -7
  69. data/test/test_deleted_source.rb +2 -2
  70. data/test/test_file_list.rb +8 -6
  71. data/test/test_filters.rb +29 -13
  72. data/test/test_merge_helpers.rb +26 -23
  73. data/test/test_result.rb +32 -23
  74. data/test/test_return_codes.rb +3 -3
  75. data/test/test_source_file.rb +4 -4
  76. data/test/test_source_file_line.rb +13 -13
  77. metadata +145 -63
  78. data/lib/simplecov/json.rb +0 -27
@@ -1,32 +1,32 @@
1
1
  #
2
2
  # Helper that tries to find out what test suite is running (for SimpleCov.command_name)
3
3
  #
4
- module SimpleCov::CommandGuesser
5
- class << self
6
- # Storage for the original command line call that invoked the test suite.
7
- # This has got to be stored as early as possible because i.e. rake and test/unit 2
8
- # have a habit of tampering with ARGV, which makes i.e. the automatic distinction
9
- # between rails unit/functional/integration tests impossible without this cached
10
- # item.
11
- attr_accessor :original_run_command
4
+ module SimpleCov
5
+ module CommandGuesser
6
+ class << self
7
+ # Storage for the original command line call that invoked the test suite.
8
+ # This has got to be stored as early as possible because i.e. rake and test/unit 2
9
+ # have a habit of tampering with ARGV, which makes i.e. the automatic distinction
10
+ # between rails unit/functional/integration tests impossible without this cached
11
+ # item.
12
+ attr_accessor :original_run_command
12
13
 
13
- def guess
14
- from_env || from_command_line_options || from_defined_constants
15
- end
14
+ def guess
15
+ from_env || from_command_line_options || from_defined_constants
16
+ end
16
17
 
17
18
  private
18
19
 
19
- def from_env
20
- # If being run from inside parallel_tests set the command name according to the process number
21
- if ENV['PARALLEL_TEST_GROUPS'] && ENV['TEST_ENV_NUMBER']
22
- number = ENV['TEST_ENV_NUMBER']
23
- number = '1' if number == ''
20
+ def from_env
21
+ # If being run from inside parallel_tests set the command name according to the process number
22
+ return unless ENV["PARALLEL_TEST_GROUPS"] && ENV["TEST_ENV_NUMBER"]
23
+ number = ENV["TEST_ENV_NUMBER"]
24
+ number = "1" if number.empty?
24
25
  "(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})"
25
26
  end
26
- end
27
27
 
28
- def from_command_line_options
29
- case original_run_command
28
+ def from_command_line_options
29
+ case original_run_command
30
30
  when /test\/functional\//, /test\/\{.*functional.*\}\//
31
31
  "Functional Tests"
32
32
  when /test\/integration\//
@@ -37,23 +37,22 @@ module SimpleCov::CommandGuesser
37
37
  "RSpec"
38
38
  when /cucumber/, /features/
39
39
  "Cucumber Features"
40
- else
41
- nil
40
+ end
42
41
  end
43
- end
44
42
 
45
- def from_defined_constants
46
- # If the command regexps fail, let's try checking defined constants.
47
- if defined?(RSpec)
48
- "RSpec"
49
- elsif defined?(Test::Unit)
50
- "Unit Tests"
51
- elsif defined?(MiniTest)
52
- "MiniTest"
53
- else
54
- # TODO: Provide link to docs/wiki article
55
- warn "SimpleCov failed to recognize the test framework and/or suite used. Please specify manually using SimpleCov.command_name 'Unit Tests'."
56
- 'Unknown Test Framework'
43
+ def from_defined_constants
44
+ # If the command regexps fail, let's try checking defined constants.
45
+ if defined?(RSpec)
46
+ "RSpec"
47
+ elsif defined?(Test::Unit)
48
+ "Unit Tests"
49
+ elsif defined?(MiniTest)
50
+ "MiniTest"
51
+ else
52
+ # TODO: Provide link to docs/wiki article
53
+ warn "SimpleCov failed to recognize the test framework and/or suite used. Please specify manually using SimpleCov.command_name 'Unit Tests'."
54
+ "Unknown Test Framework"
55
+ end
57
56
  end
58
57
  end
59
58
  end
@@ -1,268 +1,272 @@
1
- require 'fileutils'
2
- require 'docile'
3
- require 'simplecov/formatter/multi_formatter'
1
+ require "fileutils"
2
+ require "docile"
3
+ require "simplecov/formatter/multi_formatter"
4
4
  #
5
5
  # Bundles the configuration options used for SimpleCov. All methods
6
6
  # defined here are usable from SimpleCov directly. Please check out
7
7
  # SimpleCov documentation for further info.
8
8
  #
9
- module SimpleCov::Configuration
10
- attr_writer :filters, :groups, :formatter
9
+ module SimpleCov
10
+ module Configuration
11
+ attr_writer :filters, :groups, :formatter
11
12
 
12
- #
13
- # The root for the project. This defaults to the
14
- # current working directory.
15
- #
16
- # Configure with SimpleCov.root('/my/project/path')
17
- #
18
- def root(root=nil)
19
- return @root if defined? @root and root.nil?
20
- @root = File.expand_path(root || Dir.getwd)
21
- end
13
+ #
14
+ # The root for the project. This defaults to the
15
+ # current working directory.
16
+ #
17
+ # Configure with SimpleCov.root('/my/project/path')
18
+ #
19
+ def root(root = nil)
20
+ return @root if defined?(@root) && root.nil?
21
+ @root = File.expand_path(root || Dir.getwd)
22
+ end
22
23
 
23
- #
24
- # The name of the output and cache directory. Defaults to 'coverage'
25
- #
26
- # Configure with SimpleCov.coverage_dir('cov')
27
- #
28
- def coverage_dir(dir=nil)
29
- return @coverage_dir if defined? @coverage_dir and dir.nil?
30
- @coverage_dir = (dir || 'coverage')
31
- end
24
+ #
25
+ # The name of the output and cache directory. Defaults to 'coverage'
26
+ #
27
+ # Configure with SimpleCov.coverage_dir('cov')
28
+ #
29
+ def coverage_dir(dir = nil)
30
+ return @coverage_dir if defined?(@coverage_dir) && dir.nil?
31
+ @coverage_dir = (dir || "coverage")
32
+ end
32
33
 
33
- #
34
- # Returns the full path to the output directory using SimpleCov.root
35
- # and SimpleCov.coverage_dir, so you can adjust this by configuring those
36
- # values. Will create the directory if it's missing
37
- #
38
- def coverage_path
39
- coverage_path = File.expand_path(coverage_dir, root)
40
- FileUtils.mkdir_p coverage_path
41
- coverage_path
42
- end
34
+ #
35
+ # Returns the full path to the output directory using SimpleCov.root
36
+ # and SimpleCov.coverage_dir, so you can adjust this by configuring those
37
+ # values. Will create the directory if it's missing
38
+ #
39
+ def coverage_path
40
+ coverage_path = File.expand_path(coverage_dir, root)
41
+ FileUtils.mkdir_p coverage_path
42
+ coverage_path
43
+ end
43
44
 
44
- #
45
- # Returns the list of configured filters. Add filters using SimpleCov.add_filter.
46
- #
47
- def filters
48
- @filters ||= []
49
- end
45
+ #
46
+ # Returns the list of configured filters. Add filters using SimpleCov.add_filter.
47
+ #
48
+ def filters
49
+ @filters ||= []
50
+ end
50
51
 
51
- # The name of the command (a.k.a. Test Suite) currently running. Used for result
52
- # merging and caching. It first tries to make a guess based upon the command line
53
- # arguments the current test suite is running on and should automatically detect
54
- # unit tests, functional tests, integration tests, rpsec and cucumber and label
55
- # them properly. If it fails to recognize the current command, the command name
56
- # is set to the shell command that the current suite is running on.
57
- #
58
- # You can specify it manually with SimpleCov.command_name("test:units") - please
59
- # also check out the corresponding section in README.rdoc
60
- def command_name(name=nil)
61
- @name = name unless name.nil?
62
- @name ||= SimpleCov::CommandGuesser.guess
63
- @name
64
- end
52
+ # The name of the command (a.k.a. Test Suite) currently running. Used for result
53
+ # merging and caching. It first tries to make a guess based upon the command line
54
+ # arguments the current test suite is running on and should automatically detect
55
+ # unit tests, functional tests, integration tests, rpsec and cucumber and label
56
+ # them properly. If it fails to recognize the current command, the command name
57
+ # is set to the shell command that the current suite is running on.
58
+ #
59
+ # You can specify it manually with SimpleCov.command_name("test:units") - please
60
+ # also check out the corresponding section in README.rdoc
61
+ def command_name(name = nil)
62
+ @name = name unless name.nil?
63
+ @name ||= SimpleCov::CommandGuesser.guess
64
+ @name
65
+ end
65
66
 
66
- #
67
- # Gets or sets the configured formatter.
68
- #
69
- # Configure with: SimpleCov.formatter(SimpleCov::Formatter::SimpleFormatter)
70
- #
71
- def formatter(formatter=nil)
72
- return @formatter if defined? @formatter and formatter.nil?
73
- @formatter = formatter
74
- raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter
75
- @formatter
76
- end
67
+ #
68
+ # Gets or sets the configured formatter.
69
+ #
70
+ # Configure with: SimpleCov.formatter(SimpleCov::Formatter::SimpleFormatter)
71
+ #
72
+ def formatter(formatter = nil)
73
+ return @formatter if defined?(@formatter) && formatter.nil?
74
+ @formatter = formatter
75
+ fail "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter
76
+ @formatter
77
+ end
77
78
 
78
- #
79
- # Sets the configured formatters.
80
- #
81
- def formatters=(formatters)
82
- @formatter = SimpleCov::Formatter::MultiFormatter[*formatters]
83
- end
79
+ #
80
+ # Sets the configured formatters.
81
+ #
82
+ def formatters=(formatters)
83
+ @formatter = SimpleCov::Formatter::MultiFormatter[*formatters]
84
+ end
84
85
 
85
- #
86
- # Gets the configured formatters.
87
- #
88
- def formatters
89
- if @formatter.is_a?(SimpleCov::Formatter::MultiFormatter)
90
- @formatter.formatters
91
- else
92
- Array(formatter)
86
+ #
87
+ # Gets the configured formatters.
88
+ #
89
+ def formatters
90
+ if @formatter.is_a?(SimpleCov::Formatter::MultiFormatter)
91
+ @formatter.formatters
92
+ else
93
+ Array(formatter)
94
+ end
93
95
  end
94
- end
95
96
 
96
- #
97
- # Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from
98
- # the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token
99
- # can be configured to be any other string using this.
100
- #
101
- # Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip')
102
- #
103
- def nocov_token(nocov_token=nil)
104
- return @nocov_token if defined? @nocov_token and nocov_token.nil?
105
- @nocov_token = (nocov_token || 'nocov')
106
- end
107
- alias_method :skip_token, :nocov_token
97
+ #
98
+ # Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from
99
+ # the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token
100
+ # can be configured to be any other string using this.
101
+ #
102
+ # Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip')
103
+ #
104
+ def nocov_token(nocov_token = nil)
105
+ return @nocov_token if defined?(@nocov_token) && nocov_token.nil?
106
+ @nocov_token = (nocov_token || "nocov")
107
+ end
108
+ alias_method :skip_token, :nocov_token
108
109
 
109
- #
110
- # Returns the configured groups. Add groups using SimpleCov.add_group
111
- #
112
- def groups
113
- @groups ||= {}
114
- end
110
+ #
111
+ # Returns the configured groups. Add groups using SimpleCov.add_group
112
+ #
113
+ def groups
114
+ @groups ||= {}
115
+ end
115
116
 
116
- #
117
- # Returns the hash of available profiles
118
- #
119
- def profiles
120
- @profiles ||= SimpleCov::Profiles.new
121
- end
117
+ #
118
+ # Returns the hash of available profiles
119
+ #
120
+ def profiles
121
+ @profiles ||= SimpleCov::Profiles.new
122
+ end
122
123
 
123
- def adapters
124
- warn "method adapters is deprecated. use profiles instead"
125
- profiles
126
- end
124
+ def adapters
125
+ warn "method adapters is deprecated. use profiles instead"
126
+ profiles
127
+ end
127
128
 
128
- #
129
- # Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
130
- # you're calling.
131
- #
132
- # SimpleCov.configure do
133
- # add_filter 'foobar'
134
- # end
135
- #
136
- # This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure
137
- # options at once.
138
- #
139
- def configure(&block)
140
- return false unless SimpleCov.usable?
141
- Docile.dsl_eval(self, &block)
142
- end
129
+ #
130
+ # Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
131
+ # you're calling.
132
+ #
133
+ # SimpleCov.configure do
134
+ # add_filter 'foobar'
135
+ # end
136
+ #
137
+ # This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure
138
+ # options at once.
139
+ #
140
+ def configure(&block)
141
+ return false unless SimpleCov.usable?
142
+ Docile.dsl_eval(self, &block)
143
+ end
143
144
 
144
- #
145
- # Gets or sets the behavior to process coverage results.
146
- #
147
- # By default, it will call SimpleCov.result.format!
148
- #
149
- # Configure with:
150
- # SimpleCov.at_exit do
151
- # puts "Coverage done"
152
- # SimpleCov.result.format!
153
- # end
154
- #
155
- def at_exit(&block)
156
- return Proc.new {} unless running or block_given?
157
- @at_exit = block if block_given?
158
- @at_exit ||= Proc.new { SimpleCov.result.format! }
159
- end
145
+ #
146
+ # Gets or sets the behavior to process coverage results.
147
+ #
148
+ # By default, it will call SimpleCov.result.format!
149
+ #
150
+ # Configure with:
151
+ # SimpleCov.at_exit do
152
+ # puts "Coverage done"
153
+ # SimpleCov.result.format!
154
+ # end
155
+ #
156
+ def at_exit(&block)
157
+ return proc {} unless running || block_given?
158
+ @at_exit = block if block_given?
159
+ @at_exit ||= proc { SimpleCov.result.format! }
160
+ end
160
161
 
161
- #
162
- # Returns the project name - currently assuming the last dirname in
163
- # the SimpleCov.root is this.
164
- #
165
- def project_name(new_name=nil)
166
- return @project_name if defined? @project_name and @project_name and new_name.nil?
167
- @project_name = new_name if new_name.kind_of?(String)
168
- @project_name ||= File.basename(root.split('/').last).capitalize.gsub('_', ' ')
169
- end
162
+ #
163
+ # Returns the project name - currently assuming the last dirname in
164
+ # the SimpleCov.root is this.
165
+ #
166
+ def project_name(new_name = nil)
167
+ return @project_name if defined?(@project_name) && @project_name && new_name.nil?
168
+ @project_name = new_name if new_name.is_a?(String)
169
+ @project_name ||= File.basename(root.split("/").last).capitalize.gsub("_", " ")
170
+ end
170
171
 
171
- #
172
- # Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...)
173
- # are joined and combined into a single coverage report
174
- #
175
- def use_merging(use=nil)
176
- @use_merging = use unless use.nil?
177
- @use_merging = true unless defined? @use_merging and @use_merging == false
178
- end
172
+ #
173
+ # Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...)
174
+ # are joined and combined into a single coverage report
175
+ #
176
+ def use_merging(use = nil)
177
+ @use_merging = use unless use.nil?
178
+ @use_merging = true unless defined?(@use_merging) && @use_merging == false
179
+ end
179
180
 
180
- #
181
- # Defines them maximum age (in seconds) of a resultset to still be included in merged results.
182
- # i.e. If you run cucumber features, then later rake test, if the stored cucumber resultset is
183
- # more seconds ago than specified here, it won't be taken into account when merging (and is also
184
- # purged from the resultset cache)
185
- #
186
- # Of course, this only applies when merging is active (e.g. SimpleCov.use_merging is not false!)
187
- #
188
- # Default is 600 seconds (10 minutes)
189
- #
190
- # Configure with SimpleCov.merge_timeout(3600) # 1hr
191
- #
192
- def merge_timeout(seconds=nil)
193
- @merge_timeout = seconds if seconds.kind_of?(Fixnum)
194
- @merge_timeout ||= 600
195
- end
181
+ #
182
+ # Defines them maximum age (in seconds) of a resultset to still be included in merged results.
183
+ # i.e. If you run cucumber features, then later rake test, if the stored cucumber resultset is
184
+ # more seconds ago than specified here, it won't be taken into account when merging (and is also
185
+ # purged from the resultset cache)
186
+ #
187
+ # Of course, this only applies when merging is active (e.g. SimpleCov.use_merging is not false!)
188
+ #
189
+ # Default is 600 seconds (10 minutes)
190
+ #
191
+ # Configure with SimpleCov.merge_timeout(3600) # 1hr
192
+ #
193
+ def merge_timeout(seconds = nil)
194
+ @merge_timeout = seconds if seconds.is_a?(Fixnum)
195
+ @merge_timeout ||= 600
196
+ end
196
197
 
197
- #
198
- # Defines the minimum overall coverage required for the testsuite to pass.
199
- # SimpleCov will return non-zero if the current coverage is below this threshold.
200
- #
201
- # Default is 0% (disabled)
202
- #
203
- def minimum_coverage(coverage=nil)
204
- @minimum_coverage ||= (coverage || 0).to_f.round(2)
205
- end
198
+ #
199
+ # Defines the minimum overall coverage required for the testsuite to pass.
200
+ # SimpleCov will return non-zero if the current coverage is below this threshold.
201
+ #
202
+ # Default is 0% (disabled)
203
+ #
204
+ def minimum_coverage(coverage = nil)
205
+ @minimum_coverage ||= (coverage || 0).to_f.round(2)
206
+ end
206
207
 
207
- #
208
- # Defines the maximum coverage drop at once allowed for the testsuite to pass.
209
- # SimpleCov will return non-zero if the coverage decreases by more than this threshold.
210
- #
211
- # Default is 100% (disabled)
212
- #
213
- def maximum_coverage_drop(coverage_drop=nil)
214
- @maximum_coverage_drop ||= (coverage_drop || 100).to_f.round(2)
215
- end
208
+ #
209
+ # Defines the maximum coverage drop at once allowed for the testsuite to pass.
210
+ # SimpleCov will return non-zero if the coverage decreases by more than this threshold.
211
+ #
212
+ # Default is 100% (disabled)
213
+ #
214
+ def maximum_coverage_drop(coverage_drop = nil)
215
+ @maximum_coverage_drop ||= (coverage_drop || 100).to_f.round(2)
216
+ end
216
217
 
217
- #
218
- # Refuses any coverage drop. That is, coverage is only allowed to increase.
219
- # SimpleCov will return non-zero if the coverage decreases.
220
- #
221
- def refuse_coverage_drop
222
- maximum_coverage_drop 0
223
- end
218
+ #
219
+ # Refuses any coverage drop. That is, coverage is only allowed to increase.
220
+ # SimpleCov will return non-zero if the coverage decreases.
221
+ #
222
+ def refuse_coverage_drop
223
+ maximum_coverage_drop 0
224
+ end
224
225
 
225
- #
226
- # Add a filter to the processing chain.
227
- # There are three ways to define a filter:
228
- #
229
- # * as a String that will then be matched against all source files' file paths,
230
- # SimpleCov.add_filter 'app/models' # will reject all your models
231
- # * as a block which will be passed the source file in question and should either
232
- # return a true or false value, depending on whether the file should be removed
233
- # SimpleCov.add_filter do |src_file|
234
- # File.basename(src_file.filename) == 'environment.rb'
235
- # end # Will exclude environment.rb files from the results
236
- # * as an instance of a subclass of SimpleCov::Filter. See the documentation there
237
- # on how to define your own filter classes
238
- #
239
- def add_filter(filter_argument=nil, &filter_proc)
240
- filters << parse_filter(filter_argument, &filter_proc)
241
- end
226
+ #
227
+ # Add a filter to the processing chain.
228
+ # There are three ways to define a filter:
229
+ #
230
+ # * as a String that will then be matched against all source files' file paths,
231
+ # SimpleCov.add_filter 'app/models' # will reject all your models
232
+ # * as a block which will be passed the source file in question and should either
233
+ # return a true or false value, depending on whether the file should be removed
234
+ # SimpleCov.add_filter do |src_file|
235
+ # File.basename(src_file.filename) == 'environment.rb'
236
+ # end # Will exclude environment.rb files from the results
237
+ # * as an instance of a subclass of SimpleCov::Filter. See the documentation there
238
+ # on how to define your own filter classes
239
+ #
240
+ def add_filter(filter_argument = nil, &filter_proc)
241
+ filters << parse_filter(filter_argument, &filter_proc)
242
+ end
242
243
 
243
- #
244
- # Define a group for files. Works similar to add_filter, only that the first
245
- # argument is the desired group name and files PASSING the filter end up in the group
246
- # (while filters exclude when the filter is applicable).
247
- #
248
- def add_group(group_name, filter_argument=nil, &filter_proc)
249
- groups[group_name] = parse_filter(filter_argument, &filter_proc)
250
- end
244
+ #
245
+ # Define a group for files. Works similar to add_filter, only that the first
246
+ # argument is the desired group name and files PASSING the filter end up in the group
247
+ # (while filters exclude when the filter is applicable).
248
+ #
249
+ def add_group(group_name, filter_argument = nil, &filter_proc)
250
+ groups[group_name] = parse_filter(filter_argument, &filter_proc)
251
+ end
251
252
 
252
253
  private
253
254
 
254
- #
255
- # The actal filter processor. Not meant for direct use
256
- #
257
- def parse_filter(filter_argument=nil, &filter_proc)
258
- if filter_argument.kind_of?(SimpleCov::Filter)
259
- filter_argument
260
- elsif filter_argument.kind_of?(String)
261
- SimpleCov::StringFilter.new(filter_argument)
262
- elsif filter_proc
263
- SimpleCov::BlockFilter.new(filter_proc)
264
- else
265
- raise ArgumentError, "Please specify either a string or a block to filter with"
255
+ #
256
+ # The actal filter processor. Not meant for direct use
257
+ #
258
+ def parse_filter(filter_argument = nil, &filter_proc)
259
+ if filter_argument.is_a?(SimpleCov::Filter)
260
+ filter_argument
261
+ elsif filter_argument.is_a?(String)
262
+ SimpleCov::StringFilter.new(filter_argument)
263
+ elsif filter_proc
264
+ SimpleCov::BlockFilter.new(filter_proc)
265
+ elsif filter_argument.is_a?(Array)
266
+ SimpleCov::ArrayFilter.new(filter_argument)
267
+ else
268
+ fail ArgumentError, "Please specify either a string or a block to filter with"
269
+ end
266
270
  end
267
271
  end
268
272
  end