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.'
- ALLOWED_STATUSES =
%i[error success missing redirect].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
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
#node ⇒ Object
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
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
|
#current ⇒ Object
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
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
|
#message ⇒ Object
111
112
113
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 111
def message
format(MSG, prefer: prefer, current: current)
end
|
#offense_range ⇒ Object
119
120
121
|
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 119
def offense_range
node
end
|