lib/rubocop/cop/rspec/expect_actual.rb in rubocop-rspec-1.12.0 vs lib/rubocop/cop/rspec/expect_actual.rb in rubocop-rspec-1.13.0
- old
+ new
@@ -15,11 +15,11 @@
# expect(price).to eq(5)
# expect(pattern).to eq(/foo/)
# expect(name).to eq("John")
#
class ExpectActual < Cop
- MSG = 'Provide the actual you are testing to `expect(...)`'.freeze
+ MSG = 'Provide the actual you are testing to `expect(...)`.'.freeze
SIMPLE_LITERALS = %i(
true
false
nil
@@ -39,11 +39,11 @@
irange
erange
regexp
).freeze
- def_node_matcher :expect, '(send _ :expect $_)'
+ def_node_matcher :expect_literal, '(send _ :expect $#literal?)'
def on_send(node)
expect_literal(node) do |argument|
add_offense(argument, :expression)
end
@@ -51,17 +51,11 @@
private
# This is not implement using a NodePattern because it seems
# to not be able to match against an explicit (nil) sexp
- def expect_literal(node)
- return unless (argument = expect(node))
-
- yield(argument) if literal?(argument)
- end
-
def literal?(node)
- simple_literal?(node) || complex_literal?(node)
+ node && (simple_literal?(node) || complex_literal?(node))
end
def simple_literal?(node)
SIMPLE_LITERALS.include?(node.type)
end