Skip to content

Commit ccd821e

Browse files
authored
Merge pull request #13 from rubocop/fix-error3
Fix an error for `RSpecRails/HttpStatus` when no rack gem is loaded with rubocop-rspec
2 parents 81ca431 + 86a5e26 commit ccd821e

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Master (Unreleased)
44

55
- Fix a `NameError` by Cross-Referencing. ([@ydah])
6+
- Fix an error for `RSpecRails/HttpStatus` when no rack gem is loaded with rubocop-rspec. ([@ydah])
67

78
## 2.28.1 (2024-03-29)
89

lib/rubocop/cop/rspec_rails/http_status.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# frozen_string_literal: true
22

3-
require 'rack/utils'
3+
begin
4+
require 'rack/utils'
5+
rescue LoadError
6+
# RSpecRails/HttpStatus cannot be loaded if rack/utils is unavailable.
7+
end
48

59
module RuboCop
610
module Cop
@@ -64,6 +68,8 @@ class HttpStatus < ::RuboCop::Cop::RSpec::Base
6468
PATTERN
6569

6670
def on_send(node)
71+
return unless defined?(::Rack::Utils::SYMBOL_TO_STATUS_CODE)
72+
6773
http_status(node) do |arg|
6874
return if arg.str_type? && arg.heredoc?
6975

lib/rubocop/cop/rspec_rails_cops.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
require_relative 'rspec_rails/avoid_setup_hook'
44
require_relative 'rspec_rails/have_http_status'
5-
require_relative 'rspec_rails/negation_be_valid'
6-
begin
7-
require_relative 'rspec_rails/http_status'
8-
rescue LoadError
9-
# RSpecRails/HttpStatus cannot be loaded if rack/utils is unavailable.
10-
end
5+
require_relative 'rspec_rails/http_status'
116
require_relative 'rspec_rails/inferred_spec_type'
127
require_relative 'rspec_rails/minitest_assertions'
8+
require_relative 'rspec_rails/negation_be_valid'
139
require_relative 'rspec_rails/travel_around'

0 commit comments

Comments
 (0)