Class: RuboCop::Cop::RSpec::Rails::HttpStatus::StyleCheckerBase

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.'
ALLOWED_STATUSES =
%i[error success missing redirect].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ StyleCheckerBase

Returns a new instance of StyleCheckerBase.



94
95
96
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 94

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



92
93
94
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 92

def node
  @node
end

Instance Method Details

#allowed_symbol?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 106

def allowed_symbol?
  node.sym_type? && ALLOWED_STATUSES.include?(node.value)
end

#custom_http_status_code?Boolean

Returns:

  • (Boolean)


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

def custom_http_status_code?
  node.int_type? &&
    !::Rack::Utils::SYMBOL_TO_STATUS_CODE.value?(node.source.to_i)
end

#messageObject



98
99
100
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 98

def message
  format(MSG, prefer: prefer, current: current)
end

#offense_rangeObject



102
103
104
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 102

def offense_range
  node
end