Skip to content

Commit 3870bd0

Browse files
committed
Tell SimpleCov to ignore unreachable code
In some cases we know that a case statement is covering all possible branches, e.g. `case [foo?, bar?]` has four branches (if the predicate methods return booleans, of course), and `case style` has a know number of branches, depending on `SupportedStyles` in config/default.yml. So, when to use `else ... raise ArgumentError`, and when to change the last `elsif` or `when` into an `else`? I don't know.
1 parent 2e3cca0 commit 3870bd0

File tree

7 files changed

+34
-4
lines changed

7 files changed

+34
-4
lines changed

.simplecov

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SimpleCov.start do
44
enable_coverage :branch
5-
minimum_coverage line: 100, branch: 98.44
5+
minimum_coverage line: 100, branch: 100
66
add_filter '/spec/'
77
add_filter '/vendor/bundle/'
88
end

lib/rubocop/cop/rspec/be_nil.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def on_send(node)
4848
check_be_style(node)
4949
when :be_nil
5050
check_be_nil_style(node)
51+
else
52+
# :nocov:
53+
:noop
54+
# :nocov:
5155
end
5256
end
5357

lib/rubocop/cop/rspec/example_wording.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def text(node)
128128
node.node_parts.map { |child_node| text(child_node) }.join
129129
when :str
130130
node.value
131-
when :begin
131+
else
132132
node.source
133133
end
134134
end

lib/rubocop/cop/rspec/excessive_docstring_spacing.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def text(node)
100100
node.node_parts.map { |child_node| text(child_node) }.join
101101
when :str, :sym
102102
node.value
103-
when :begin
103+
else
104104
node.source
105105
end
106106
end

lib/rubocop/cop/rspec/implicit_subject.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def on_send(node)
9797

9898
private
9999

100+
# rubocop:disable Metrics/MethodLength
100101
def autocorrect(corrector, node)
101102
case node.method_name
102103
when :expect
@@ -107,8 +108,13 @@ def autocorrect(corrector, node)
107108
corrector.replace(node.location.selector, 'expect(subject).to')
108109
when :should_not
109110
corrector.replace(node.location.selector, 'expect(subject).not_to')
111+
else
112+
# :nocov:
113+
:noop
114+
# :nocov:
110115
end
111116
end
117+
# rubocop:enable Metrics/MethodLength
112118

113119
def message(_node)
114120
case style
@@ -119,6 +125,7 @@ def message(_node)
119125
end
120126
end
121127

128+
# rubocop:disable Metrics/MethodLength
122129
def invalid?(node)
123130
case style
124131
when :require_implicit
@@ -129,8 +136,13 @@ def invalid?(node)
129136
implicit_subject_in_non_its_and_non_single_line?(node)
130137
when :single_statement_only
131138
implicit_subject_in_non_its_and_non_single_statement?(node)
139+
else
140+
# :nocov:
141+
:noop
142+
# :nocov:
132143
end
133144
end
145+
# rubocop:enable Metrics/MethodLength
134146

135147
def implicit_subject_in_non_its?(node)
136148
implicit_subject?(node) && !its?(node)

lib/rubocop/cop/rspec/message_spies.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def error_message(receiver)
8080
MSG_RECEIVE
8181
when :have_received
8282
format(MSG_HAVE_RECEIVED, source: receiver.source)
83+
else
84+
# :nocov:
85+
:noop
86+
# :nocov:
8387
end
8488
end
8589
end

lib/rubocop/cop/rspec/predicate_matcher.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def rewrite_matcher(corrector, predicate, matcher)
110110
)
111111
end
112112

113+
# rubocop:disable Metrics/MethodLength
113114
def true?(to_symbol, matcher)
114115
result = case matcher.method_name
115116
when :be, :eq, :eql, :equal
@@ -118,9 +119,14 @@ def true?(to_symbol, matcher)
118119
true
119120
when :be_falsey, :be_falsy, :a_falsey_value, :a_falsy_value
120121
false
122+
else
123+
# :nocov:
124+
:noop
125+
# :nocov:
121126
end
122127
to_symbol == :to ? result : !result
123128
end
129+
# rubocop:enable Metrics/MethodLength
124130
end
125131

126132
# A helper for `explicit` style
@@ -266,7 +272,7 @@ def replacement_matcher(node)
266272
'be(false)'
267273
when [false, true]
268274
'be_truthy'
269-
when [false, false]
275+
else
270276
'be_falsey'
271277
end
272278
end
@@ -335,6 +341,10 @@ def on_send(node)
335341
check_inflected(node)
336342
when :explicit
337343
check_explicit(node)
344+
else
345+
# :nocov:
346+
:noop
347+
# :nocov:
338348
end
339349
end
340350

0 commit comments

Comments
 (0)