Class: RuboCop::Cop::RSpecRails::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.



107
108
109
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 107

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



105
106
107
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 105

def node
  @node
end

Instance Method Details

#allowed_symbol?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 123

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

#currentObject



115
116
117
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 115

def current
  offense_range.source
end

#custom_http_status_code?Boolean

Returns:

  • (Boolean)


127
128
129
130
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 127

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

#messageObject



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

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

#offense_rangeObject



119
120
121
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 119

def offense_range
  node
end