Class: RuboCop::Cop::Homebrew::NoInstanceVariableAccessInTests Private

Inherits:
Base
  • Object
show all
Defined in:
rubocops/no_instance_variable_access_in_tests.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Flags instance_variable_get/instance_variable_set in tests. Tests should read and write object state through public accessors: add a public attr_reader/ attr_writer (or use an existing accessor) on the class instead of reaching into its instance variables.

Example

# bad
formula.instance_variable_set(:@tap, CoreTap.instance)

# good (with a public `attr_writer :tap`)
formula.tap = CoreTap.instance

Constant Summary collapse

MSG =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"Use a public `attr_reader`/`attr_writer` (or an existing accessor) instead of " \
"`%<method>s` in tests."
RESTRICT_ON_SEND =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

[:instance_variable_get, :instance_variable_set].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ void Also known as: on_csend

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::SendNode)


27
28
29
# File 'rubocops/no_instance_variable_access_in_tests.rb', line 27

def on_send(node)
  add_offense(node.loc.selector, message: format(MSG, method: node.method_name))
end