lib/rubocop/cop/rspec/implicit_subject.rb in rubocop-rspec-1.42.0 vs lib/rubocop/cop/rspec/implicit_subject.rb in rubocop-rspec-1.43.0
- old
+ new
@@ -24,11 +24,11 @@
# it { is_expected.to be_truthy }
#
# # good
# it { expect(subject).to be_truthy }
#
- class ImplicitSubject < Cop
+ class ImplicitSubject < Base
extend AutoCorrector
include ConfigurableEnforcedStyle
MSG = "Don't use implicit subject."
@@ -47,29 +47,31 @@
private
def autocorrect(corrector, node)
replacement = 'expect(subject)'
- if node.method_name == :should
+ case node.method_name
+ when :should
replacement += '.to'
- elsif node.method_name == :should_not
+ when :should_not
replacement += '.not_to'
end
corrector.replace(node.loc.selector, replacement)
end
def valid_usage?(node)
example = node.ancestors.find { |parent| example?(parent) }
return false if example.nil?
- example.method_name == :its || allowed_by_style?(example)
+ example.method?(:its) || allowed_by_style?(example)
end
def allowed_by_style?(example)
- if style == :single_line_only
+ case style
+ when :single_line_only
example.single_line?
- elsif style == :single_statement_only
+ when :single_statement_only
!example.body.begin_type?
else
false
end
end