Class: RuboCop::Cop::RSpecRails::HttpStatus::StyleCheckerBase
- Inherits:
-
Object
- Object
- RuboCop::Cop::RSpecRails::HttpStatus::StyleCheckerBase
show all
- Defined in:
- lib/rubocop/cop/rspec_rails/http_status.rb
Overview
Constant Summary
collapse
- MSG =
'Prefer `%<prefer>s` over `%<current>s` ' \
'to describe HTTP status code.'
- MSG_UNKNOWN_STATUS_CODE =
'Unknown status code.'
- ALLOWED_STATUSES =
%i[error success missing redirect].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of StyleCheckerBase.
121
122
123
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 121
def initialize(node)
@node = node
end
|
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node.
119
120
121
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 119
def node
@node
end
|
Instance Method Details
#allowed_symbol? ⇒ Boolean
141
142
143
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 141
def allowed_symbol?
node.sym_type? && ALLOWED_STATUSES.include?(node.value)
end
|
#current ⇒ Object
133
134
135
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 133
def current
offense_range.source
end
|
#custom_http_status_code? ⇒ Boolean
145
146
147
148
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 145
def custom_http_status_code?
node.int_type? &&
!::Rack::Utils::SYMBOL_TO_STATUS_CODE.value?(node.source.to_i)
end
|
#message ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 125
def message
if autocorrectable?
format(MSG, prefer: prefer, current: current)
else
MSG_UNKNOWN_STATUS_CODE
end
end
|
#offense_range ⇒ Object
137
138
139
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 137
def offense_range
node
end
|