Skip to content

Fix an error for RSpecRails/HttpStatus when no rack gem is loaded with rubocop-rspec #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::SYMBOL_TO_STATUS_CODE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The performance of this line could probably be optimized, but given that it’s a temporary change I think it’s fine.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bquorning Good catch, 👍


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'