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.'
ALLOWED_STATUSES =
%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.



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

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

Instance Method Details

#messageObject



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

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

#offensive?Boolean

Returns:

  • (Boolean)


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

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

#preferred_styleObject



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

def preferred_style
  number.to_s
end