Class: RuboCop::Cop::RSpec::Rails::HttpStatus::NumericStyleChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/rails/http_status.rb

Overview

:nodoc:

Constant Summary collapse

MSG =
'Prefer `%<prefer>s` over `%<current>s` ' \
'to describe HTTP status code.'.freeze
WHITELIST_STATUS =
i[error success missing redirect].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ NumericStyleChecker

Returns a new instance of NumericStyleChecker.



112
113
114
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 112

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



111
112
113
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 111

def node
  @node
end

Instance Method Details

#messageObject



120
121
122
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 120

def message
  format(MSG, prefer: preferred_style, current: symbol.inspect)
end

#offensive?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 116

def offensive?
  !node.int_type? && !whitelisted_symbol?
end

#preferred_styleObject



124
125
126
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 124

def preferred_style
  number.to_s
end