simplecov 0.8.0.pre2 → 0.18.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +368 -27
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +38 -7
  5. data/ISSUE_TEMPLATE.md +23 -0
  6. data/{MIT-LICENSE → LICENSE} +1 -1
  7. data/README.md +449 -230
  8. data/doc/alternate-formatters.md +61 -0
  9. data/doc/commercial-services.md +20 -0
  10. data/doc/editor-integration.md +18 -0
  11. data/lib/simplecov.rb +294 -59
  12. data/lib/simplecov/combine.rb +30 -0
  13. data/lib/simplecov/combine/branches_combiner.rb +32 -0
  14. data/lib/simplecov/combine/files_combiner.rb +25 -0
  15. data/lib/simplecov/combine/lines_combiner.rb +43 -0
  16. data/lib/simplecov/combine/results_combiner.rb +60 -0
  17. data/lib/simplecov/command_guesser.rb +46 -40
  18. data/lib/simplecov/configuration.rb +346 -221
  19. data/lib/simplecov/defaults.rb +35 -75
  20. data/lib/simplecov/exit_codes.rb +9 -4
  21. data/lib/simplecov/file_list.rb +80 -36
  22. data/lib/simplecov/filter.rb +51 -3
  23. data/lib/simplecov/formatter.rb +4 -2
  24. data/lib/simplecov/formatter/multi_formatter.rb +28 -19
  25. data/lib/simplecov/formatter/simple_formatter.rb +21 -15
  26. data/lib/simplecov/last_run.rb +21 -13
  27. data/lib/simplecov/lines_classifier.rb +48 -0
  28. data/lib/simplecov/load_global_config.rb +8 -0
  29. data/lib/simplecov/no_defaults.rb +4 -2
  30. data/lib/simplecov/profiles.rb +29 -23
  31. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  32. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  33. data/lib/simplecov/profiles/rails.rb +18 -0
  34. data/lib/simplecov/profiles/root_filter.rb +10 -0
  35. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  36. data/lib/simplecov/result.rb +39 -68
  37. data/lib/simplecov/result_adapter.rb +30 -0
  38. data/lib/simplecov/result_merger.rb +110 -60
  39. data/lib/simplecov/simulate_coverage.rb +29 -0
  40. data/lib/simplecov/source_file.rb +261 -135
  41. data/lib/simplecov/source_file/branch.rb +106 -0
  42. data/lib/simplecov/source_file/line.rb +72 -0
  43. data/lib/simplecov/useless_results_remover.rb +16 -0
  44. data/lib/simplecov/version.rb +4 -2
  45. metadata +48 -197
  46. data/.gitignore +0 -32
  47. data/.travis.yml +0 -28
  48. data/.yardopts +0 -1
  49. data/Appraisals +0 -8
  50. data/Gemfile +0 -16
  51. data/Rakefile +0 -32
  52. data/cucumber.yml +0 -13
  53. data/features/config_autoload.feature +0 -46
  54. data/features/config_command_name.feature +0 -45
  55. data/features/config_coverage_dir.feature +0 -33
  56. data/features/config_deactivate_merging.feature +0 -42
  57. data/features/config_formatters.feature +0 -52
  58. data/features/config_merge_timeout.feature +0 -39
  59. data/features/config_nocov_token.feature +0 -79
  60. data/features/config_profiles.feature +0 -44
  61. data/features/config_project_name.feature +0 -27
  62. data/features/config_styles.feature +0 -121
  63. data/features/cucumber_basic.feature +0 -29
  64. data/features/maximum_coverage_drop.feature +0 -36
  65. data/features/merging_test_unit_and_rspec.feature +0 -44
  66. data/features/minimum_coverage.feature +0 -59
  67. data/features/refuse_coverage_drop.feature +0 -35
  68. data/features/rspec_basic.feature +0 -31
  69. data/features/rspec_fails_on_initialization.feature +0 -14
  70. data/features/rspec_groups_and_filters_basic.feature +0 -29
  71. data/features/rspec_groups_and_filters_complex.feature +0 -35
  72. data/features/rspec_groups_using_filter_class.feature +0 -40
  73. data/features/rspec_without_simplecov.feature +0 -20
  74. data/features/skipping_code_blocks_manually.feature +0 -70
  75. data/features/step_definitions/html_steps.rb +0 -45
  76. data/features/step_definitions/simplecov_steps.rb +0 -66
  77. data/features/step_definitions/transformers.rb +0 -13
  78. data/features/step_definitions/web_steps.rb +0 -64
  79. data/features/support/env.rb +0 -44
  80. data/features/test_unit_basic.feature +0 -34
  81. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  82. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  83. data/features/test_unit_groups_using_filter_class.feature +0 -40
  84. data/features/test_unit_without_simplecov.feature +0 -20
  85. data/features/unicode_compatiblity.feature +0 -67
  86. data/gemfiles/multi_json_legacy.gemfile +0 -12
  87. data/gemfiles/multi_json_new.gemfile +0 -12
  88. data/lib/simplecov/jruby16_fix.rb +0 -43
  89. data/lib/simplecov/json.rb +0 -27
  90. data/lib/simplecov/merge_helpers.rb +0 -39
  91. data/lib/simplecov/railtie.rb +0 -7
  92. data/lib/simplecov/railties/tasks.rake +0 -11
  93. data/simplecov.gemspec +0 -30
  94. data/test/faked_project/Gemfile +0 -6
  95. data/test/faked_project/Rakefile +0 -8
  96. data/test/faked_project/cucumber.yml +0 -13
  97. data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
  98. data/test/faked_project/features/support/env.rb +0 -12
  99. data/test/faked_project/features/test_stuff.feature +0 -6
  100. data/test/faked_project/lib/faked_project.rb +0 -11
  101. data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
  102. data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
  103. data/test/faked_project/lib/faked_project/some_class.rb +0 -29
  104. data/test/faked_project/spec/faked_spec.rb +0 -11
  105. data/test/faked_project/spec/meta_magic_spec.rb +0 -10
  106. data/test/faked_project/spec/some_class_spec.rb +0 -10
  107. data/test/faked_project/spec/spec_helper.rb +0 -15
  108. data/test/faked_project/test/faked_test.rb +0 -11
  109. data/test/faked_project/test/meta_magic_test.rb +0 -13
  110. data/test/faked_project/test/some_class_test.rb +0 -15
  111. data/test/faked_project/test/test_helper.rb +0 -16
  112. data/test/fixtures/app/controllers/sample_controller.rb +0 -10
  113. data/test/fixtures/app/models/user.rb +0 -10
  114. data/test/fixtures/deleted_source_sample.rb +0 -15
  115. data/test/fixtures/frameworks/rspec_bad.rb +0 -9
  116. data/test/fixtures/frameworks/rspec_good.rb +0 -9
  117. data/test/fixtures/frameworks/testunit_bad.rb +0 -9
  118. data/test/fixtures/frameworks/testunit_good.rb +0 -9
  119. data/test/fixtures/iso-8859.rb +0 -3
  120. data/test/fixtures/resultset1.rb +0 -4
  121. data/test/fixtures/resultset2.rb +0 -5
  122. data/test/fixtures/sample.rb +0 -16
  123. data/test/fixtures/utf-8.rb +0 -3
  124. data/test/helper.rb +0 -34
  125. data/test/shoulda_macros.rb +0 -19
  126. data/test/test_1_8_fallbacks.rb +0 -31
  127. data/test/test_command_guesser.rb +0 -19
  128. data/test/test_deleted_source.rb +0 -14
  129. data/test/test_file_list.rb +0 -22
  130. data/test/test_filters.rb +0 -78
  131. data/test/test_merge_helpers.rb +0 -105
  132. data/test/test_result.rb +0 -160
  133. data/test/test_return_codes.rb +0 -37
  134. data/test/test_source_file.rb +0 -106
  135. data/test/test_source_file_line.rb +0 -106
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ #
5
+ # Responsible for producing file coverage metrics.
6
+ #
7
+ module SimulateCoverage
8
+ module_function
9
+
10
+ #
11
+ # Simulate normal file coverage report on
12
+ # ruby 2.5 and return similar hash with lines and branches keys
13
+ #
14
+ # Happens when a file wasn't required but still tracked.
15
+ #
16
+ # @return [Hash]
17
+ #
18
+ def call(absolute_path)
19
+ lines = File.foreach(absolute_path)
20
+
21
+ {
22
+ :lines => LinesClassifier.new.classify(lines),
23
+ # we don't want to parse branches ourselves...
24
+ # requiring files can have side effects and we don't want to trigger that
25
+ :branches => {}
26
+ }
27
+ end
28
+ end
29
+ end
@@ -1,187 +1,313 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  #
3
5
  # Representation of a source file including it's coverage data, source code,
4
6
  # source lines and featuring helpers to interpret that data.
5
7
  #
6
8
  class SourceFile
7
- # Representation of a single line in a source file including
8
- # this specific line's source code, line_number and code coverage,
9
- # with the coverage being either nil (coverage not applicable, e.g. comment
10
- # line), 0 (line not covered) or >1 (the amount of times the line was
11
- # executed)
12
- class Line
13
- # The source code for this line. Aliased as :source
14
- attr_reader :src
15
- # The line number in the source file. Aliased as :line, :number
16
- attr_reader :line_number
17
- # The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered)
18
- attr_reader :coverage
19
- # Whether this line was skipped
20
- attr_reader :skipped
21
-
22
- # Lets grab some fancy aliases, shall we?
23
- alias_method :source, :src
24
- alias_method :line, :line_number
25
- alias_method :number, :line_number
26
-
27
- def initialize(src, line_number, coverage)
28
- raise ArgumentError, "Only String accepted for source" unless src.kind_of?(String)
29
- raise ArgumentError, "Only Fixnum accepted for line_number" unless line_number.kind_of?(Fixnum)
30
- raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil?
31
- @src, @line_number, @coverage = src, line_number, coverage
32
- @skipped = false
33
- end
34
-
35
- # Returns true if this is a line that should have been covered, but was not
36
- def missed?
37
- not never? and not skipped? and coverage == 0
38
- end
39
-
40
- # Returns true if this is a line that has been covered
41
- def covered?
42
- not never? and not skipped? and coverage > 0
43
- end
44
-
45
- # Returns true if this line is not relevant for coverage
46
- def never?
47
- not skipped? and coverage.nil?
48
- end
49
-
50
- # Flags this line as skipped
51
- def skipped!
52
- @skipped = true
53
- end
54
-
55
- # Returns true if this line was skipped, false otherwise. Lines are skipped if they are wrapped with
56
- # # :nocov: comment lines.
57
- def skipped?
58
- !!skipped
59
- end
60
-
61
- # The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use
62
- # as a css class in report generation
63
- def status
64
- return 'skipped' if skipped?
65
- return 'never' if never?
66
- return 'missed' if missed?
67
- return 'covered' if covered?
68
- end
69
- end
70
-
71
9
  # The full path to this source file (e.g. /User/colszowka/projects/simplecov/lib/simplecov/source_file.rb)
72
10
  attr_reader :filename
73
11
  # The array of coverage data received from the Coverage.result
74
12
  attr_reader :coverage
75
- # The source code for this file. Aliased as :source
76
- attr_reader :src
77
- alias_method :source, :src
78
13
 
79
14
  def initialize(filename, coverage)
80
- @filename, @coverage = filename, coverage
81
- File.open(filename, "rb") {|f| @src = f.readlines }
15
+ @filename = filename.to_s
16
+ @coverage = coverage
82
17
  end
83
18
 
19
+ # The path to this source file relative to the projects directory
20
+ def project_filename
21
+ @filename.sub(Regexp.new("^#{Regexp.escape(SimpleCov.root)}"), "")
22
+ end
23
+
24
+ # The source code for this file. Aliased as :source
25
+ def src
26
+ # We intentionally read source code lazily to
27
+ # suppress reading unused source code.
28
+ @src ||= File.open(filename, "rb", &:readlines)
29
+ end
30
+ alias source src
31
+
84
32
  # Returns all source lines for this file as instances of SimpleCov::SourceFile::Line,
85
33
  # and thus including coverage data. Aliased as :source_lines
86
34
  def lines
87
- return @lines if defined? @lines
35
+ @lines ||= build_lines
36
+ end
37
+ alias source_lines lines
38
+
39
+ # Returns all covered lines as SimpleCov::SourceFile::Line
40
+ def covered_lines
41
+ @covered_lines ||= lines.select(&:covered?)
42
+ end
88
43
 
89
- # Warning to identify condition from Issue #56
90
- if coverage.size > src.size
91
- $stderr.puts "Warning: coverage data provided by Coverage [#{coverage.size}] exceeds number of lines in #{filename} [#{src.size}]"
44
+ # Returns all lines that should have been, but were not covered
45
+ # as instances of SimpleCov::SourceFile::Line
46
+ def missed_lines
47
+ @missed_lines ||= lines.select(&:missed?)
48
+ end
49
+
50
+ # Returns all lines that are not relevant for coverage as
51
+ # SimpleCov::SourceFile::Line instances
52
+ def never_lines
53
+ @never_lines ||= lines.select(&:never?)
54
+ end
55
+
56
+ # Returns all lines that were skipped as SimpleCov::SourceFile::Line instances
57
+ def skipped_lines
58
+ @skipped_lines ||= lines.select(&:skipped?)
59
+ end
60
+
61
+ # Returns the number of relevant lines (covered + missed)
62
+ def lines_of_code
63
+ covered_lines.size + missed_lines.size
64
+ end
65
+
66
+ def build_lines
67
+ coverage_exceeding_source_warn if coverage[:lines].size > src.size
68
+ lines = src.map.with_index(1) do |src, i|
69
+ SimpleCov::SourceFile::Line.new(src, i, coverage[:lines][i - 1])
92
70
  end
71
+ process_skipped_lines(lines)
72
+ end
73
+
74
+ # no_cov_chunks is zero indexed to work directly with the array holding the lines
75
+ def no_cov_chunks
76
+ @no_cov_chunks ||= build_no_cov_chunks
77
+ end
93
78
 
94
- # Initialize lines
95
- @lines = []
96
- src.each_with_index do |src, i|
97
- @lines << SimpleCov::SourceFile::Line.new(src, i+1, coverage[i])
79
+ def build_no_cov_chunks
80
+ no_cov_lines = src.map.with_index(1).select { |line, _index| LinesClassifier.no_cov_line?(line) }
81
+
82
+ warn "uneven number of nocov comments detected" if no_cov_lines.size.odd?
83
+
84
+ no_cov_lines.each_slice(2).map do |(_line_start, index_start), (_line_end, index_end)|
85
+ index_start..index_end
98
86
  end
99
- process_skipped_lines!
100
- @lines
101
87
  end
102
- alias_method :source_lines, :lines
88
+
89
+ def process_skipped_lines(lines)
90
+ # the array the lines are kept in is 0-based whereas the line numbers in the nocov
91
+ # chunks are 1-based and are expected to be like this in other parts (and it's also
92
+ # arguably more understandable)
93
+ no_cov_chunks.each { |chunk| lines[(chunk.begin - 1)..(chunk.end - 1)].each(&:skipped!) }
94
+
95
+ lines
96
+ end
97
+
98
+ # Warning to identify condition from Issue #56
99
+ def coverage_exceeding_source_warn
100
+ warn "Warning: coverage data provided by Coverage [#{coverage[:lines].size}] exceeds number of lines in #{filename} [#{src.size}]"
101
+ end
103
102
 
104
103
  # Access SimpleCov::SourceFile::Line source lines by line number
105
104
  def line(number)
106
- lines[number-1]
105
+ lines[number - 1]
107
106
  end
108
107
 
109
- # The coverage for this file in percent. 0 if the file has no relevant lines
108
+ # The coverage for this file in percent. 0 if the file has no coverage lines
110
109
  def covered_percent
111
- return 100.0 if lines.length == 0 or lines.length == never_lines.count
112
- relevant_lines = lines.count - never_lines.count - skipped_lines.count
113
- if relevant_lines == 0
114
- 0
115
- else
116
- (covered_lines.count) * 100.0 / relevant_lines.to_f
117
- end
110
+ return 100.0 if no_lines?
111
+
112
+ return 0.0 if relevant_lines.zero?
113
+
114
+ Float(covered_lines.size * 100.0 / relevant_lines.to_f)
118
115
  end
119
116
 
120
117
  def covered_strength
121
- return 0 if lines.length == 0 or lines.length == never_lines.count
118
+ return 0.0 if relevant_lines.zero?
119
+
120
+ (lines_strength / relevant_lines.to_f).round(1)
121
+ end
122
+
123
+ def no_lines?
124
+ lines.length.zero? || (lines.length == never_lines.size)
125
+ end
126
+
127
+ def lines_strength
128
+ lines.map(&:coverage).compact.reduce(:+)
129
+ end
130
+
131
+ def relevant_lines
132
+ lines.size - never_lines.size - skipped_lines.size
133
+ end
134
+
135
+ #
136
+ # Return all the branches inside current source file
137
+ def branches
138
+ @branches ||= build_branches
139
+ end
122
140
 
123
- lines_strength = 0
124
- lines.each do |c|
125
- lines_strength += c.coverage if c.coverage
141
+ def no_branches?
142
+ total_branches.empty?
143
+ end
144
+
145
+ def branches_coverage_percent
146
+ return 100.0 if no_branches?
147
+ return 0.0 if covered_branches.empty?
148
+
149
+ Float(covered_branches.size * 100.0 / total_branches.size.to_f)
150
+ end
151
+
152
+ #
153
+ # Return the relevant branches to source file
154
+ def total_branches
155
+ covered_branches + missed_branches
156
+ end
157
+
158
+ #
159
+ # Return hash with key of line number and branch coverage count as value
160
+ def branches_report
161
+ @branches_report ||= build_branches_report
162
+ end
163
+
164
+ ## Related to source file branches statistics
165
+
166
+ #
167
+ # Call recursive method that transform our static hash to array of objects
168
+ # @return [Array]
169
+ #
170
+ def build_branches
171
+ coverage_branch_data = coverage.fetch(:branches, {})
172
+ branches = coverage_branch_data.flat_map do |condition, coverage_branches|
173
+ build_branches_from(condition, coverage_branches)
126
174
  end
127
175
 
128
- effective_lines_count = (lines.count - never_lines.count - skipped_lines.count).to_f
176
+ process_skipped_branches(branches)
177
+ end
178
+
179
+ def process_skipped_branches(branches)
180
+ return branches if no_cov_chunks.empty?
129
181
 
130
- if effective_lines_count == 0
131
- 0
132
- else
133
- strength = lines_strength / effective_lines_count
134
- round_float(strength, 1)
182
+ branches.each do |branch|
183
+ branch.skipped! if no_cov_chunks.any? { |no_cov_chunk| branch.overlaps_with?(no_cov_chunk) }
135
184
  end
185
+
186
+ branches
136
187
  end
137
188
 
138
- # Returns all covered lines as SimpleCov::SourceFile::Line
139
- def covered_lines
140
- @covered_lines ||= lines.select {|c| c.covered? }
189
+ # Since we are dumping to and loading from JSON, and we have arrays as keys those
190
+ # don't make their way back to us intact e.g. just as a string or a symbol (currently keys are symbolized).
191
+ #
192
+ # We should probably do something different here, but as it stands these are
193
+ # our data structures that we write so eval isn't _too_ bad.
194
+ #
195
+ # See #801
196
+ #
197
+ def restore_ruby_data_structure(structure)
198
+ # Tests use the real data structures (except for integration tests) so no need to
199
+ # put them through here.
200
+ return structure if structure.is_a?(Array)
201
+
202
+ # as of right now the keys are still symbolized
203
+ # rubocop:disable Security/Eval
204
+ eval structure.to_s
205
+ # rubocop:enable Security/Eval
141
206
  end
142
207
 
143
- # Returns all lines that should have been, but were not covered
144
- # as instances of SimpleCov::SourceFile::Line
145
- def missed_lines
146
- @missed_lines ||= lines.select {|c| c.missed? }
208
+ def build_branches_from(condition, branches)
209
+ # the format handed in from the coverage data is like this:
210
+ #
211
+ # [:then, 4, 6, 6, 6, 10]
212
+ #
213
+ # which is [type, id, start_line, start_col, end_line, end_col]
214
+ condition_type, condition_id, condition_start_line, * = restore_ruby_data_structure(condition)
215
+
216
+ branches
217
+ .map { |branch_data, hit_count| [restore_ruby_data_structure(branch_data), hit_count] }
218
+ .reject { |branch_data, _hit_count| ignore_branch?(branch_data, condition_type, condition_start_line) }
219
+ .map { |branch_data, hit_count| build_branch(branch_data, hit_count, condition_start_line, condition_id) }
147
220
  end
148
221
 
149
- # Returns all lines that are not relevant for coverage as
150
- # SimpleCov::SourceFile::Line instances
151
- def never_lines
152
- @never_lines ||= lines.select {|c| c.never? }
222
+ def build_branch(branch_data, hit_count, condition_start_line, condition_id)
223
+ type, id, start_line, _start_col, end_line, _end_col = branch_data
224
+
225
+ SourceFile::Branch.new(
226
+ # rubocop these are keyword args please let me keep them, thank you
227
+ # rubocop:disable Style/HashSyntax
228
+ start_line: start_line,
229
+ end_line: end_line,
230
+ coverage: hit_count,
231
+ inline: start_line == condition_start_line,
232
+ positive: positive_branch?(condition_id, id, type)
233
+ # rubocop:enable Style/HashSyntax
234
+ )
153
235
  end
154
236
 
155
- # Returns all lines that were skipped as SimpleCov::SourceFile::Line instances
156
- def skipped_lines
157
- @skipped_lines ||= lines.select {|c| c.skipped? }
237
+ def ignore_branch?(branch_data, condition_type, condition_start_line)
238
+ branch_type = branch_data[0]
239
+ branch_start_line = branch_data[2]
240
+
241
+ # branch coverage always reports case to be with an else branch even when
242
+ # there is no else branch to be covered, it's noticable by the reported start
243
+ # line being the same as that of the condition/case
244
+ condition_type == :case &&
245
+ branch_type == :else &&
246
+ condition_start_line == branch_start_line
158
247
  end
159
248
 
160
- # Returns the number of relevant lines (covered + missed)
161
- def lines_of_code
162
- covered_lines.count + missed_lines.count
163
- end
164
-
165
- # Will go through all source files and mark lines that are wrapped within # :nocov: comment blocks
166
- # as skipped.
167
- def process_skipped_lines!
168
- skipping = false
169
- lines.each do |line|
170
- if line.src =~ /^([\s]*)#([\s]*)(\:#{SimpleCov.nocov_token}\:)/
171
- skipping = !skipping
172
- else
173
- line.skipped! if skipping
174
- end
175
- end
249
+ #
250
+ # Branch is positive or negative.
251
+ # For `case` conditions, `when` always supposed as positive branch.
252
+ # For `if, else` conditions:
253
+ # coverage returns matrices ex: [:if, 0,..] => {[:then, 1,..], [:else, 2,..]},
254
+ # positive branch always has id equals to condition id incremented by 1.
255
+ #
256
+ # @return [Boolean]
257
+ #
258
+ def positive_branch?(condition_id, branch_id, branch_type)
259
+ return true if branch_type == :when
260
+
261
+ branch_id == (1 + condition_id)
176
262
  end
177
263
 
178
- private
264
+ #
265
+ # Select the covered branches
266
+ # Here we user tree schema because some conditions like case may have additional
267
+ # else that is not in declared inside the code but given by default by coverage report
268
+ #
269
+ # @return [Array]
270
+ #
271
+ def covered_branches
272
+ @covered_branches ||= branches.select(&:covered?)
273
+ end
274
+
275
+ #
276
+ # Select the missed branches with coverage equal to zero
277
+ #
278
+ # @return [Array]
279
+ #
280
+ def missed_branches
281
+ @missed_branches ||= branches.select(&:missed?)
282
+ end
179
283
 
180
- # ruby 1.9 could use Float#round(places) instead
181
- def round_float(float, places)
182
- factor = (10 * places).to_f
183
- (float * factor).round / factor
284
+ def branches_for_line(line_number)
285
+ branches_report.fetch(line_number, [])
286
+ end
287
+
288
+ #
289
+ # Check if any branches missing on given line number
290
+ #
291
+ # @param [Integer] line_number
292
+ #
293
+ # @return [Boolean]
294
+ #
295
+ def line_with_missed_branch?(line_number)
296
+ branches_for_line(line_number).select { |count, _sign| count.zero? }.any?
297
+ end
298
+
299
+ #
300
+ # Build full branches report
301
+ # Root branches represent the wrapper of all condition state that
302
+ # have inside the branches
303
+ #
304
+ # @return [Hash]
305
+ #
306
+ def build_branches_report
307
+ branches.reject(&:skipped?).each_with_object({}) do |branch, coverage_statistics|
308
+ coverage_statistics[branch.report_line] ||= []
309
+ coverage_statistics[branch.report_line] << branch.report
310
+ end
184
311
  end
185
312
  end
186
313
  end
187
-