Skip to content

Commit

Permalink
Fix an error for RSpecRails/HttpStatus when no rack gem is loaded w…
Browse files Browse the repository at this point in the history
…ith rubocop-rspec
  • Loading branch information
ydah committed Mar 30, 2024
1 parent 81ca431 commit dc924e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

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

## 2.28.1 (2024-03-29)

Expand Down
8 changes: 7 additions & 1 deletion lib/rubocop/cop/rspec_rails/http_status.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

require 'rack/utils'
begin
require 'rack/utils'
rescue LoadError
# RSpecRails/HttpStatus cannot be loaded if rack/utils is unavailable.
end

module RuboCop
module Cop
Expand Down Expand Up @@ -64,6 +68,8 @@ class HttpStatus < ::RuboCop::Cop::RSpec::Base
PATTERN

def on_send(node)
return unless defined?(::Rack::Utils)

http_status(node) do |arg|
return if arg.str_type? && arg.heredoc?

Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/cop/rspec_rails_cops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

require_relative 'rspec_rails/avoid_setup_hook'
require_relative 'rspec_rails/have_http_status'
require_relative 'rspec_rails/negation_be_valid'
begin
require_relative 'rspec_rails/http_status'
rescue LoadError
# RSpecRails/HttpStatus cannot be loaded if rack/utils is unavailable.
end
require_relative 'rspec_rails/http_status'
require_relative 'rspec_rails/inferred_spec_type'
require_relative 'rspec_rails/minitest_assertions'
require_relative 'rspec_rails/negation_be_valid'
require_relative 'rspec_rails/travel_around'

0 comments on commit dc924e7

Please sign in to comment.