From 3c9500fe8ed79ed8dc6745f6a774e618cbacf162 Mon Sep 17 00:00:00 2001 From: Masataka Pocke Kuwabara Date: Tue, 12 Feb 2019 12:19:08 +0900 Subject: [PATCH] Add `rack` to runtime dependency --- lib/rubocop-rails.rb | 1 + lib/rubocop/cop/rails/http_status.rb | 23 ++---------- rubocop-rails.gemspec | 2 +- spec/rubocop/cop/rails/http_status_spec.rb | 41 ---------------------- 4 files changed, 4 insertions(+), 63 deletions(-) diff --git a/lib/rubocop-rails.rb b/lib/rubocop-rails.rb index d20839339b..a2a921e304 100644 --- a/lib/rubocop-rails.rb +++ b/lib/rubocop-rails.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'rubocop' +require 'rack/utils' require_relative 'rubocop/rails/version' require_relative 'rubocop/cop/rails_cops' diff --git a/lib/rubocop/cop/rails/http_status.rb b/lib/rubocop/cop/rails/http_status.rb index af3e7bff50..571bf56117 100644 --- a/lib/rubocop/cop/rails/http_status.rb +++ b/lib/rubocop/cop/rails/http_status.rb @@ -32,13 +32,6 @@ module Rails # redirect_to root_url, status: 301 # class HttpStatus < Cop - begin - require 'rack/utils' - RACK_LOADED = true - rescue LoadError - RACK_LOADED = false - end - include ConfigurableEnforcedStyle def_node_matcher :http_status, <<-PATTERN @@ -64,10 +57,6 @@ def on_send(node) end end - def support_autocorrect? - RACK_LOADED - end - def autocorrect(node) lambda do |corrector| checker = checker_class.new(node) @@ -110,11 +99,7 @@ def offensive? end def message - if RACK_LOADED - format(MSG, prefer: preferred_style, current: number.to_s) - else - DEFAULT_MSG - end + format(MSG, prefer: preferred_style, current: number.to_s) end def preferred_style @@ -155,11 +140,7 @@ def offensive? end def message - if RACK_LOADED - format(MSG, prefer: preferred_style, current: symbol.inspect) - else - DEFAULT_MSG - end + format(MSG, prefer: preferred_style, current: symbol.inspect) end def preferred_style diff --git a/rubocop-rails.gemspec b/rubocop-rails.gemspec index be6b8bf070..64f7667180 100644 --- a/rubocop-rails.gemspec +++ b/rubocop-rails.gemspec @@ -31,7 +31,7 @@ Gem::Specification.new do |s| 'bug_tracker_uri' => 'https://github.com/rubocop-hq/rubocop-rails/issues' } + s.add_runtime_dependency 'rack', '>= 2.0' s.add_runtime_dependency 'rubocop', '>= 0.58.0' - s.add_development_dependency('rack', '>= 2.0') end # rubocop:enable Metrics/BlockLength diff --git a/spec/rubocop/cop/rails/http_status_spec.rb b/spec/rubocop/cop/rails/http_status_spec.rb index da5763b7a4..550d25dd7a 100644 --- a/spec/rubocop/cop/rails/http_status_spec.rb +++ b/spec/rubocop/cop/rails/http_status_spec.rb @@ -49,30 +49,6 @@ redirect_to root_url, status: 550 RUBY end - - context 'when rack is not loaded' do - before { stub_const("#{described_class}::RACK_LOADED", false) } - - it 'registers an offense and does not correct using numeric value' do - expect_offense(<<-RUBY) - render :foo, status: 200 - ^^^ Prefer `symbolic` over `numeric` to define HTTP status code. - render json: { foo: 'bar' }, status: 404 - ^^^ Prefer `symbolic` over `numeric` to define HTTP status code. - render plain: 'foo/bar', status: 304 - ^^^ Prefer `symbolic` over `numeric` to define HTTP status code. - redirect_to root_url, status: 301 - ^^^ Prefer `symbolic` over `numeric` to define HTTP status code. - RUBY - - expect_correction(<<-RUBY) - render :foo, status: 200 - render json: { foo: 'bar' }, status: 404 - render plain: 'foo/bar', status: 304 - redirect_to root_url, status: 301 - RUBY - end - end end context 'when EnforcedStyle is `numeric`' do @@ -121,22 +97,5 @@ render :foo, status: :redirect RUBY end - - context 'when rack is not loaded' do - before { stub_const("#{described_class}::RACK_LOADED", false) } - - it 'registers an offense and corrects using symbolic value' do - expect_offense(<<-RUBY) - render :foo, status: :ok - ^^^ Prefer `numeric` over `symbolic` to define HTTP status code. - render json: { foo: 'bar' }, status: :not_found - ^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code. - render plain: 'foo/bar', status: :not_modified - ^^^^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code. - redirect_to root_url, status: :moved_permanently - ^^^^^^^^^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code. - RUBY - end - end end end