From b4f25a45fe6913b0f64ce0d730291854f5cb8145 Mon Sep 17 00:00:00 2001 From: ydah Date: Sun, 31 Mar 2024 02:01:12 +0900 Subject: [PATCH] Fix an error for unrecognized cop or department `RSpecRails/HttpStatus` when also using rubocop-rails Fix: https://github.com/rubocop/rubocop-rspec_rails/issues/8 --- CHANGELOG.md | 1 + lib/rubocop-rspec_rails.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fad62d70..d3889e02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix a `NameError` by Cross-Referencing. ([@ydah]) - Fix an error for `RSpecRails/HttpStatus` when no rack gem is loaded with rubocop-rspec. ([@ydah]) +- Fix an error for unrecognized cop or department `RSpecRails/HttpStatus` when also using rubocop-rails. ([@ydah]) ## 2.28.1 (2024-03-29) diff --git a/lib/rubocop-rspec_rails.rb b/lib/rubocop-rspec_rails.rb index 3feb4e2f..41e401b5 100644 --- a/lib/rubocop-rspec_rails.rb +++ b/lib/rubocop-rspec_rails.rb @@ -16,3 +16,20 @@ project_root = File.join(__dir__, '..') RuboCop::ConfigLoader.inject_defaults!(project_root) + +# FIXME: This is a workaround for the following issue: +# https://github.com/rubocop/rubocop-rspec_rails/issues/8 +module RuboCop + module Cop + class AmbiguousCopName # rubocop:disable Style/Documentation + prepend(Module.new do + def qualified_cop_name(name, path, warn: true) + return super unless name == 'RSpec/Rails/HttpStatus' + + badge = Badge.parse(name) + resolve_badge(badge, qualify_badge(badge).first, path) + end + end) + end + end +end