simplecov 0.6.4 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +378 -12
  3. data/CONTRIBUTING.md +51 -0
  4. data/ISSUE_TEMPLATE.md +23 -0
  5. data/LICENSE +1 -1
  6. data/README.md +456 -252
  7. data/doc/alternate-formatters.md +56 -0
  8. data/doc/commercial-services.md +20 -0
  9. data/doc/editor-integration.md +18 -0
  10. data/lib/simplecov.rb +223 -44
  11. data/lib/simplecov/command_guesser.rb +47 -35
  12. data/lib/simplecov/configuration.rb +281 -191
  13. data/lib/simplecov/defaults.rb +38 -43
  14. data/lib/simplecov/exit_codes.rb +10 -0
  15. data/lib/simplecov/file_list.rb +51 -34
  16. data/lib/simplecov/filter.rb +50 -3
  17. data/lib/simplecov/formatter.rb +4 -1
  18. data/lib/simplecov/formatter/multi_formatter.rb +34 -0
  19. data/lib/simplecov/formatter/simple_formatter.rb +18 -12
  20. data/lib/simplecov/jruby_fix.rb +44 -0
  21. data/lib/simplecov/last_run.rb +26 -0
  22. data/lib/simplecov/lines_classifier.rb +48 -0
  23. data/lib/simplecov/load_global_config.rb +8 -0
  24. data/lib/simplecov/no_defaults.rb +4 -0
  25. data/lib/simplecov/profiles.rb +33 -0
  26. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  27. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  28. data/lib/simplecov/profiles/rails.rb +18 -0
  29. data/lib/simplecov/profiles/root_filter.rb +10 -0
  30. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  31. data/lib/simplecov/railtie.rb +3 -1
  32. data/lib/simplecov/railties/tasks.rake +9 -7
  33. data/lib/simplecov/raw_coverage.rb +41 -0
  34. data/lib/simplecov/result.rb +17 -55
  35. data/lib/simplecov/result_merger.rb +100 -67
  36. data/lib/simplecov/source_file.rb +82 -67
  37. data/lib/simplecov/version.rb +4 -2
  38. metadata +153 -222
  39. data/.gitignore +0 -31
  40. data/.travis.yml +0 -15
  41. data/Appraisals +0 -8
  42. data/Gemfile +0 -5
  43. data/Rakefile +0 -19
  44. data/cucumber.yml +0 -13
  45. data/features/config_adapters.feature +0 -44
  46. data/features/config_autoload.feature +0 -46
  47. data/features/config_command_name.feature +0 -33
  48. data/features/config_coverage_dir.feature +0 -20
  49. data/features/config_deactivate_merging.feature +0 -42
  50. data/features/config_merge_timeout.feature +0 -39
  51. data/features/config_nocov_token.feature +0 -79
  52. data/features/config_project_name.feature +0 -27
  53. data/features/config_styles.feature +0 -93
  54. data/features/cucumber_basic.feature +0 -29
  55. data/features/merging_test_unit_and_rspec.feature +0 -44
  56. data/features/rspec_basic.feature +0 -31
  57. data/features/rspec_fails_on_initialization.feature +0 -14
  58. data/features/rspec_groups_and_filters_basic.feature +0 -29
  59. data/features/rspec_groups_and_filters_complex.feature +0 -35
  60. data/features/rspec_groups_using_filter_class.feature +0 -40
  61. data/features/rspec_without_simplecov.feature +0 -20
  62. data/features/skipping_code_blocks_manually.feature +0 -70
  63. data/features/step_definitions/html_steps.rb +0 -45
  64. data/features/step_definitions/simplecov_steps.rb +0 -66
  65. data/features/step_definitions/transformers.rb +0 -13
  66. data/features/step_definitions/web_steps.rb +0 -64
  67. data/features/support/env.rb +0 -26
  68. data/features/test_unit_basic.feature +0 -34
  69. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  70. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  71. data/features/test_unit_groups_using_filter_class.feature +0 -40
  72. data/features/test_unit_without_simplecov.feature +0 -20
  73. data/features/unicode_compatiblity.feature +0 -67
  74. data/gemfiles/multi_json-legacy.gemfile +0 -7
  75. data/gemfiles/multi_json-legacy.gemfile.lock +0 -85
  76. data/gemfiles/multi_json-new.gemfile +0 -7
  77. data/gemfiles/multi_json-new.gemfile.lock +0 -85
  78. data/lib/simplecov/adapters.rb +0 -29
  79. data/lib/simplecov/merge_helpers.rb +0 -39
  80. data/simplecov.gemspec +0 -29
  81. data/test/faked_project/Gemfile +0 -6
  82. data/test/faked_project/Rakefile +0 -8
  83. data/test/faked_project/cucumber.yml +0 -13
  84. data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
  85. data/test/faked_project/features/support/env.rb +0 -12
  86. data/test/faked_project/features/test_stuff.feature +0 -6
  87. data/test/faked_project/lib/faked_project.rb +0 -11
  88. data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
  89. data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
  90. data/test/faked_project/lib/faked_project/some_class.rb +0 -29
  91. data/test/faked_project/spec/faked_spec.rb +0 -11
  92. data/test/faked_project/spec/meta_magic_spec.rb +0 -10
  93. data/test/faked_project/spec/some_class_spec.rb +0 -10
  94. data/test/faked_project/spec/spec_helper.rb +0 -15
  95. data/test/faked_project/test/faked_test.rb +0 -11
  96. data/test/faked_project/test/meta_magic_test.rb +0 -13
  97. data/test/faked_project/test/some_class_test.rb +0 -15
  98. data/test/faked_project/test/test_helper.rb +0 -16
  99. data/test/fixtures/app/controllers/sample_controller.rb +0 -10
  100. data/test/fixtures/app/models/user.rb +0 -10
  101. data/test/fixtures/deleted_source_sample.rb +0 -15
  102. data/test/fixtures/frameworks/rspec_bad.rb +0 -9
  103. data/test/fixtures/frameworks/rspec_good.rb +0 -9
  104. data/test/fixtures/frameworks/testunit_bad.rb +0 -9
  105. data/test/fixtures/frameworks/testunit_good.rb +0 -9
  106. data/test/fixtures/iso-8859.rb +0 -3
  107. data/test/fixtures/resultset1.rb +0 -4
  108. data/test/fixtures/resultset2.rb +0 -5
  109. data/test/fixtures/sample.rb +0 -16
  110. data/test/fixtures/utf-8.rb +0 -3
  111. data/test/helper.rb +0 -35
  112. data/test/shoulda_macros.rb +0 -29
  113. data/test/test_1_8_fallbacks.rb +0 -33
  114. data/test/test_command_guesser.rb +0 -21
  115. data/test/test_deleted_source.rb +0 -16
  116. data/test/test_file_list.rb +0 -24
  117. data/test/test_filters.rb +0 -80
  118. data/test/test_merge_helpers.rb +0 -107
  119. data/test/test_result.rb +0 -147
  120. data/test/test_return_codes.rb +0 -39
  121. data/test/test_source_file.rb +0 -95
  122. data/test/test_source_file_line.rb +0 -110
@@ -1,215 +1,305 @@
1
- require 'fileutils'
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "docile"
5
+ require "simplecov/formatter/multi_formatter"
2
6
  #
3
7
  # Bundles the configuration options used for SimpleCov. All methods
4
8
  # defined here are usable from SimpleCov directly. Please check out
5
9
  # SimpleCov documentation for further info.
6
10
  #
7
- module SimpleCov::Configuration
8
- attr_writer :filters, :groups, :formatter
9
-
10
- #
11
- # The root for the project. This defaults to the
12
- # current working directory.
13
- #
14
- # Configure with SimpleCov.root('/my/project/path')
15
- #
16
- def root(root=nil)
17
- return @root if defined? @root and root.nil?
18
- @root = File.expand_path(root || Dir.getwd)
19
- end
11
+ module SimpleCov
12
+ module Configuration # rubocop:disable ModuleLength
13
+ attr_writer :filters, :groups, :formatter
20
14
 
21
- #
22
- # The name of the output and cache directory. Defaults to 'coverage'
23
- #
24
- # Configure with SimpleCov.coverage_dir('cov')
25
- #
26
- def coverage_dir(dir=nil)
27
- return @coverage_dir if defined? @coverage_dir and dir.nil?
28
- @coverage_dir = (dir || 'coverage')
29
- end
15
+ #
16
+ # The root for the project. This defaults to the
17
+ # current working directory.
18
+ #
19
+ # Configure with SimpleCov.root('/my/project/path')
20
+ #
21
+ def root(root = nil)
22
+ return @root if defined?(@root) && root.nil?
23
+ @root = File.expand_path(root || Dir.getwd)
24
+ end
30
25
 
31
- #
32
- # Returns the full path to the output directory using SimpleCov.root
33
- # and SimpleCov.coverage_dir, so you can adjust this by configuring those
34
- # values. Will create the directory if it's missing
35
- #
36
- def coverage_path
37
- coverage_path = File.join(root, coverage_dir)
38
- FileUtils.mkdir_p coverage_path
39
- coverage_path
40
- end
26
+ #
27
+ # The name of the output and cache directory. Defaults to 'coverage'
28
+ #
29
+ # Configure with SimpleCov.coverage_dir('cov')
30
+ #
31
+ def coverage_dir(dir = nil)
32
+ return @coverage_dir if defined?(@coverage_dir) && dir.nil?
33
+ @coverage_path = nil # invalidate cache
34
+ @coverage_dir = (dir || "coverage")
35
+ end
41
36
 
42
- #
43
- # Returns the list of configured filters. Add filters using SimpleCov.add_filter.
44
- #
45
- def filters
46
- @filters ||= []
47
- end
37
+ #
38
+ # Returns the full path to the output directory using SimpleCov.root
39
+ # and SimpleCov.coverage_dir, so you can adjust this by configuring those
40
+ # values. Will create the directory if it's missing
41
+ #
42
+ def coverage_path
43
+ @coverage_path ||= begin
44
+ coverage_path = File.expand_path(coverage_dir, root)
45
+ FileUtils.mkdir_p coverage_path
46
+ coverage_path
47
+ end
48
+ end
48
49
 
49
- # The name of the command (a.k.a. Test Suite) currently running. Used for result
50
- # merging and caching. It first tries to make a guess based upon the command line
51
- # arguments the current test suite is running on and should automatically detect
52
- # unit tests, functional tests, integration tests, rpsec and cucumber and label
53
- # them properly. If it fails to recognize the current command, the command name
54
- # is set to the shell command that the current suite is running on.
55
- #
56
- # You can specify it manually with SimpleCov.command_name("test:units") - please
57
- # also check out the corresponding section in README.rdoc
58
- def command_name(name=nil)
59
- @name = name unless name.nil?
60
- @name ||= SimpleCov::CommandGuesser.guess
61
- @name
62
- end
63
-
64
- #
65
- # Gets or sets the configured formatter.
66
- #
67
- # Configure with: SimpleCov.formatter(SimpleCov::Formatter::SimpleFormatter)
68
- #
69
- def formatter(formatter=nil)
70
- return @formatter if defined? @formatter and formatter.nil?
71
- @formatter = formatter
72
- raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter
73
- @formatter
74
- end
50
+ #
51
+ # Coverage results will always include files matched by this glob, whether
52
+ # or not they were explicitly required. Without this, un-required files
53
+ # will not be present in the final report.
54
+ #
55
+ def track_files(glob)
56
+ @tracked_files = glob
57
+ end
75
58
 
76
- #
77
- # Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from
78
- # the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token
79
- # can be configured to be any other string using this.
80
- #
81
- # Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip')
82
- #
83
- def nocov_token(nocov_token=nil)
84
- return @nocov_token if defined? @nocov_token and nocov_token.nil?
85
- @nocov_token = (nocov_token || 'nocov')
86
- end
87
- alias_method :skip_token, :nocov_token
59
+ #
60
+ # Returns the glob that will be used to include files that were not
61
+ # explicitly required.
62
+ #
63
+ def tracked_files
64
+ @tracked_files if defined?(@tracked_files)
65
+ end
88
66
 
89
- #
90
- # Returns the configured groups. Add groups using SimpleCov.add_group
91
- #
92
- def groups
93
- @groups ||= {}
94
- end
67
+ #
68
+ # Returns the list of configured filters. Add filters using SimpleCov.add_filter.
69
+ #
70
+ def filters
71
+ @filters ||= []
72
+ end
95
73
 
96
- #
97
- # Returns the hash of available adapters
98
- #
99
- def adapters
100
- @adapters ||= SimpleCov::Adapters.new
101
- end
74
+ # The name of the command (a.k.a. Test Suite) currently running. Used for result
75
+ # merging and caching. It first tries to make a guess based upon the command line
76
+ # arguments the current test suite is running on and should automatically detect
77
+ # unit tests, functional tests, integration tests, rpsec and cucumber and label
78
+ # them properly. If it fails to recognize the current command, the command name
79
+ # is set to the shell command that the current suite is running on.
80
+ #
81
+ # You can specify it manually with SimpleCov.command_name("test:units") - please
82
+ # also check out the corresponding section in README.rdoc
83
+ def command_name(name = nil)
84
+ @name = name unless name.nil?
85
+ @name ||= SimpleCov::CommandGuesser.guess
86
+ @name
87
+ end
102
88
 
103
- #
104
- # Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
105
- # you're calling.
106
- #
107
- # SimpleCov.configure do
108
- # add_filter 'foobar'
109
- # end
110
- #
111
- # This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a buchn of configure
112
- # options at once.
113
- #
114
- def configure(&block)
115
- return false unless SimpleCov.usable?
116
- instance_exec(&block)
117
- end
89
+ #
90
+ # Gets or sets the configured formatter.
91
+ #
92
+ # Configure with: SimpleCov.formatter(SimpleCov::Formatter::SimpleFormatter)
93
+ #
94
+ def formatter(formatter = nil)
95
+ return @formatter if defined?(@formatter) && formatter.nil?
96
+ @formatter = formatter
97
+ raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter
98
+ @formatter
99
+ end
118
100
 
119
- #
120
- # Gets or sets the behavior to process coverage results.
121
- #
122
- # By default, it will call SimpleCov.result.format!
123
- #
124
- # Configure with:
125
- # SimpleCov.at_exit do
126
- # puts "Coverage done"
127
- # SimpleCov.result.format!
128
- # end
129
- #
130
- def at_exit(&block)
131
- return Proc.new {} unless running or block_given?
132
- @at_exit = block if block_given?
133
- @at_exit ||= Proc.new { SimpleCov.result.format! }
134
- end
101
+ #
102
+ # Sets the configured formatters.
103
+ #
104
+ def formatters=(formatters)
105
+ @formatter = SimpleCov::Formatter::MultiFormatter.new(formatters)
106
+ end
135
107
 
136
- #
137
- # Returns the project name - currently assuming the last dirname in
138
- # the SimpleCov.root is this.
139
- #
140
- def project_name(new_name=nil)
141
- return @project_name if @project_name and new_name.nil?
142
- @project_name = new_name if new_name.kind_of?(String)
143
- @project_name ||= File.basename(root.split('/').last).capitalize.gsub('_', ' ')
144
- end
108
+ #
109
+ # Gets the configured formatters.
110
+ #
111
+ def formatters
112
+ if @formatter.is_a?(SimpleCov::Formatter::MultiFormatter)
113
+ @formatter.formatters
114
+ else
115
+ Array(formatter)
116
+ end
117
+ end
145
118
 
146
- #
147
- # Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...)
148
- # are joined and combined into a single coverage report
149
- #
150
- def use_merging(use=nil)
151
- @use_merging = use unless use.nil? # Set if param given
152
- @use_merging = true if @use_merging != false
153
- end
119
+ #
120
+ # Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from
121
+ # the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token
122
+ # can be configured to be any other string using this.
123
+ #
124
+ # Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip')
125
+ #
126
+ def nocov_token(nocov_token = nil)
127
+ return @nocov_token if defined?(@nocov_token) && nocov_token.nil?
128
+ @nocov_token = (nocov_token || "nocov")
129
+ end
130
+ alias skip_token nocov_token
154
131
 
155
- #
156
- # Defines them maximum age (in seconds) of a resultset to still be included in merged results.
157
- # i.e. If you run cucumber features, then later rake test, if the stored cucumber resultset is
158
- # more seconds ago than specified here, it won't be taken into account when merging (and is also
159
- # purged from the resultset cache)
160
- #
161
- # Of course, this only applies when merging is active (e.g. SimpleCov.use_merging is not false!)
162
- #
163
- # Default is 600 seconds (10 minutes)
164
- #
165
- # Configure with SimpleCov.merge_timeout(3600) # 1hr
166
- #
167
- def merge_timeout(seconds=nil)
168
- @merge_timeout = seconds if !seconds.nil? and seconds.kind_of?(Fixnum)
169
- @merge_timeout ||= 600
170
- end
132
+ #
133
+ # Returns the configured groups. Add groups using SimpleCov.add_group
134
+ #
135
+ def groups
136
+ @groups ||= {}
137
+ end
171
138
 
172
- #
173
- # Add a filter to the processing chain.
174
- # There are three ways to define a filter:
175
- #
176
- # * as a String that will then be matched against all source files' file paths,
177
- # SimpleCov.add_filter 'app/models' # will reject all your models
178
- # * as a block which will be passed the source file in question and should either
179
- # return a true or false value, depending on whether the file should be removed
180
- # SimpleCov.add_filter do |src_file|
181
- # File.basename(src_file.filename) == 'environment.rb'
182
- # end # Will exclude environment.rb files from the results
183
- # * as an instance of a subclass of SimpleCov::Filter. See the documentation there
184
- # on how to define your own filter classes
185
- #
186
- def add_filter(filter_argument=nil, &filter_proc)
187
- filters << parse_filter(filter_argument, &filter_proc)
188
- end
139
+ #
140
+ # Returns the hash of available profiles
141
+ #
142
+ def profiles
143
+ @profiles ||= SimpleCov::Profiles.new
144
+ end
145
+
146
+ def adapters
147
+ warn "#{Kernel.caller.first}: [DEPRECATION] #adapters is deprecated. Use #profiles instead."
148
+ profiles
149
+ end
150
+
151
+ #
152
+ # Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
153
+ # you're calling.
154
+ #
155
+ # SimpleCov.configure do
156
+ # add_filter 'foobar'
157
+ # end
158
+ #
159
+ # This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure
160
+ # options at once.
161
+ #
162
+ def configure(&block)
163
+ return false unless SimpleCov.usable?
164
+ Docile.dsl_eval(self, &block)
165
+ end
166
+
167
+ #
168
+ # Gets or sets the behavior to process coverage results.
169
+ #
170
+ # By default, it will call SimpleCov.result.format!
171
+ #
172
+ # Configure with:
173
+ #
174
+ # SimpleCov.at_exit do
175
+ # puts "Coverage done"
176
+ # SimpleCov.result.format!
177
+ # end
178
+ #
179
+ def at_exit(&block)
180
+ return proc {} unless running || block_given?
181
+ @at_exit = block if block_given?
182
+ @at_exit ||= proc { SimpleCov.result.format! }
183
+ end
184
+
185
+ #
186
+ # Returns the project name - currently assuming the last dirname in
187
+ # the SimpleCov.root is this.
188
+ #
189
+ def project_name(new_name = nil)
190
+ return @project_name if defined?(@project_name) && @project_name && new_name.nil?
191
+ @project_name = new_name if new_name.is_a?(String)
192
+ @project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ")
193
+ end
194
+
195
+ #
196
+ # Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...)
197
+ # are joined and combined into a single coverage report
198
+ #
199
+ def use_merging(use = nil)
200
+ @use_merging = use unless use.nil?
201
+ @use_merging = true unless defined?(@use_merging) && @use_merging == false
202
+ end
203
+
204
+ #
205
+ # Defines the maximum age (in seconds) of a resultset to still be included in merged results.
206
+ # i.e. If you run cucumber features, then later rake test, if the stored cucumber resultset is
207
+ # more seconds ago than specified here, it won't be taken into account when merging (and is also
208
+ # purged from the resultset cache)
209
+ #
210
+ # Of course, this only applies when merging is active (e.g. SimpleCov.use_merging is not false!)
211
+ #
212
+ # Default is 600 seconds (10 minutes)
213
+ #
214
+ # Configure with SimpleCov.merge_timeout(3600) # 1hr
215
+ #
216
+ def merge_timeout(seconds = nil)
217
+ @merge_timeout = seconds if seconds.is_a?(Integer)
218
+ @merge_timeout ||= 600
219
+ end
220
+
221
+ #
222
+ # Defines the minimum overall coverage required for the testsuite to pass.
223
+ # SimpleCov will return non-zero if the current coverage is below this threshold.
224
+ #
225
+ # Default is 0% (disabled)
226
+ #
227
+ def minimum_coverage(coverage = nil)
228
+ @minimum_coverage ||= (coverage || 0).to_f.round(2)
229
+ end
230
+
231
+ #
232
+ # Defines the maximum coverage drop at once allowed for the testsuite to pass.
233
+ # SimpleCov will return non-zero if the coverage decreases by more than this threshold.
234
+ #
235
+ # Default is 100% (disabled)
236
+ #
237
+ def maximum_coverage_drop(coverage_drop = nil)
238
+ @maximum_coverage_drop ||= (coverage_drop || 100).to_f.round(2)
239
+ end
240
+
241
+ #
242
+ # Defines the minimum coverage per file required for the testsuite to pass.
243
+ # SimpleCov will return non-zero if the current coverage of the least covered file
244
+ # is below this threshold.
245
+ #
246
+ # Default is 0% (disabled)
247
+ #
248
+ def minimum_coverage_by_file(coverage = nil)
249
+ @minimum_coverage_by_file ||= (coverage || 0).to_f.round(2)
250
+ end
251
+
252
+ #
253
+ # Refuses any coverage drop. That is, coverage is only allowed to increase.
254
+ # SimpleCov will return non-zero if the coverage decreases.
255
+ #
256
+ def refuse_coverage_drop
257
+ maximum_coverage_drop 0
258
+ end
259
+
260
+ #
261
+ # Add a filter to the processing chain.
262
+ # There are four ways to define a filter:
263
+ #
264
+ # * as a String that will then be matched against all source files' file paths,
265
+ # SimpleCov.add_filter 'app/models' # will reject all your models
266
+ # * as a block which will be passed the source file in question and should either
267
+ # return a true or false value, depending on whether the file should be removed
268
+ # SimpleCov.add_filter do |src_file|
269
+ # File.basename(src_file.filename) == 'environment.rb'
270
+ # end # Will exclude environment.rb files from the results
271
+ # * as an array of strings that are matched against all sorce files' file
272
+ # paths and then ignored (basically string filter multiple times)
273
+ # SimpleCov.add_filter ['app/models', 'app/helpers'] # ignores both dirs
274
+ # * as an instance of a subclass of SimpleCov::Filter. See the documentation there
275
+ # on how to define your own filter classes
276
+ #
277
+ def add_filter(filter_argument = nil, &filter_proc)
278
+ filters << parse_filter(filter_argument, &filter_proc)
279
+ end
280
+
281
+ #
282
+ # Define a group for files. Works similar to add_filter, only that the first
283
+ # argument is the desired group name and files PASSING the filter end up in the group
284
+ # (while filters exclude when the filter is applicable).
285
+ #
286
+ def add_group(group_name, filter_argument = nil, &filter_proc)
287
+ groups[group_name] = parse_filter(filter_argument, &filter_proc)
288
+ end
189
289
 
190
- #
191
- # Define a group for files. Works similar to add_filter, only that the first
192
- # argument is the desired group name and files PASSING the filter end up in the group
193
- # (while filters exclude when the filter is applicable).
194
- #
195
- def add_group(group_name, filter_argument=nil, &filter_proc)
196
- groups[group_name] = parse_filter(filter_argument, &filter_proc)
197
- end
198
-
199
290
  private
200
291
 
201
- #
202
- # The actal filter processor. Not meant for direct use
203
- #
204
- def parse_filter(filter_argument=nil, &filter_proc)
205
- if filter_argument.kind_of?(SimpleCov::Filter)
206
- filter_argument
207
- elsif filter_argument.kind_of?(String)
208
- SimpleCov::StringFilter.new(filter_argument)
209
- elsif filter_proc
210
- SimpleCov::BlockFilter.new(filter_proc)
211
- else
212
- raise ArgumentError, "Please specify either a string or a block to filter with"
292
+ #
293
+ # The actual filter processor. Not meant for direct use
294
+ #
295
+ def parse_filter(filter_argument = nil, &filter_proc)
296
+ filter = filter_argument || filter_proc
297
+
298
+ if filter
299
+ SimpleCov::Filter.build_filter(filter)
300
+ else
301
+ raise ArgumentError, "Please specify either a filter or a block to filter with"
302
+ end
213
303
  end
214
304
  end
215
305
  end