Sha256: fa9fbbb34ed3887e35598a98964b8aa965712731a69e35bf9aeb54566c98cca8
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 KB
Contents
# encoding: utf-8 module RuboCop module Cop module RSpec # Pefer instance doubles over stubbing any instance of a class # # @example # # bad # describe MyClass do # before { allow_any_instance_of(MyClass).to receive(:foo) } # end # # # good # describe MyClass do # let(:my_instance) { instance_double(MyClass) } # # before do # allow(MyClass).to receive(:new).and_return(my_instance) # allow(my_instance).to receive(:foo) # end # end class AnyInstance < Cop MESSAGE = 'Avoid stubbing using `%{method}`'.freeze ANY_INSTANCE_METHODS = [ :any_instance, :allow_any_instance_of, :expect_any_instance_of ].freeze def on_send(node) _receiver, method_name, *_args = *node return unless ANY_INSTANCE_METHODS.include?(method_name) add_offense(node, :expression, format(MESSAGE % { method: method_name }, node.loc.expression.source ) ) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-rspec-1.4.1 | lib/rubocop/cop/rspec/any_instance.rb |
rubocop-rspec-1.4.0 | lib/rubocop/cop/rspec/any_instance.rb |