lib/rubocop/cop/rspec/let_setup.rb in rubocop-rspec-1.42.0 vs lib/rubocop/cop/rspec/let_setup.rb in rubocop-rspec-1.43.0
- old
+ new
@@ -23,21 +23,24 @@
# before { create(:widget) }
#
# it 'counts widgets' do
# expect(Widget.count).to eq(1)
# end
- class LetSetup < Cop
+ class LetSetup < Base
MSG = 'Do not use `let!` to setup objects not referenced in tests.'
def_node_matcher :example_or_shared_group_or_including?,
(
ExampleGroups::ALL + SharedGroups::ALL +
Includes::ALL
).block_pattern
def_node_matcher :let_bang, <<-PATTERN
- (block $(send nil? :let! (sym $_)) args ...)
+ {
+ (block $(send nil? :let! {(sym $_) (str $_)}) ...)
+ $(send nil? :let! {(sym $_) (str $_)} block_pass)
+ }
PATTERN
def_node_search :method_called?, '(send nil? %)'
def on_block(node)
@@ -50,10 +53,10 @@
private
def unused_let_bang(node)
child_let_bang(node) do |method_send, method_name|
- yield(method_send) unless method_called?(node, method_name)
+ yield(method_send) unless method_called?(node, method_name.to_sym)
end
end
def child_let_bang(node, &block)
RuboCop::RSpec::ExampleGroup.new(node).lets.each do |let|