Class: RuboCop::Cop::RSpec::VariableDefinition

Inherits:
Base
  • Object
show all
Includes:
ConfigurableEnforcedStyle, Variable
Defined in:
lib/rubocop/cop/rspec/variable_definition.rb

Overview

Checks that memoized helpers names are symbols or strings.

Examples:

EnforcedStyle: symbols (default)

# bad
subject('user') { create_user }
let('user_name') { 'Adam' }

# good
subject(:user) { create_user }
let(:user_name) { 'Adam' }

EnforcedStyle: strings

# bad
subject(:user) { create_user }
let(:user_name) { 'Adam' }

# good
subject('user') { create_user }
let('user_name') { 'Adam' }

Constant Summary collapse

MSG =
'Use %<style>s for variable names.'

Constants included from Variable

RuboCop::Cop::RSpec::Variable::Helpers, RuboCop::Cop::RSpec::Variable::Subjects

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Instance Method Details

#on_send(node) ⇒ Object


31
32
33
34
35
36
37
# File 'lib/rubocop/cop/rspec/variable_definition.rb', line 31

def on_send(node)
  variable_definition?(node) do |variable|
    if style_violation?(variable)
      add_offense(variable, message: format(MSG, style: style))
    end
  end
end