{"record":{"id":"6bd859c81c6decbb","repo":"CanCanCommunity/cancancan","slug":"rspec-3-will-not-be-supported-in-the-cancancan","errorCode":null,"errorMessage":"RSpec < 3 will not be supported in the CanCanCan >= 2.0.0","messagePattern":"RSpec < 3 will not be supported in the CanCanCan >= 2\\.0\\.0","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/cancan/matchers.rb","lineNumber":9,"sourceCode":"# frozen_string_literal: true\n\nrspec_module = defined?(RSpec::Core) ? 'RSpec' : 'Spec' # RSpec 1 compatability\n\nif rspec_module == 'RSpec'\n  require 'rspec/core'\n  require 'rspec/expectations'\nelse\n  ActiveSupport::Deprecation.warn('RSpec < 3 will not be supported in the CanCanCan >= 2.0.0')\nend\n\nKernel.const_get(rspec_module)::Matchers.define :be_able_to do |*args|\n  match do |ability|\n    actions = args.first\n    if actions.is_a? Array\n      if actions.empty?\n        false\n      else\n        actions.all? { |action| ability.can?(action, *args[1..-1]) }\n      end\n    else\n      ability.can?(*args)\n    end\n  end\n\n  # Check that RSpec is < 2.99\n  if !respond_to?(:failure_message) && respond_to?(:failure_message_for_should)","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/CanCanCommunity/cancancan/blob/8c1bf153a3da7b2261d6fa4a5f84eb28e2feb828/lib/cancan/matchers.rb#L1-L27","documentation":"lib/cancan/matchers.rb detects whether RSpec::Core (RSpec 2/3+) or the legacy Spec constant (RSpec 1) is defined. On the legacy path it emits ActiveSupport::Deprecation.warn('RSpec < 3 will not be supported in the CanCanCan >= 2.0.0') (lib/cancan/matchers.rb:9) and then defines be_able_to against the old Spec::Matchers API. It is a deprecation warning, not a raised exception — specs still run.","triggerScenarios":"Gemfile pins rspec or rspec-rails to a 1.x/2.x release (exposing the Spec constant without RSpec::Core), and spec_helper requires 'cancan/matchers' to get be_able_to; Bundler resolves an ancient rspec transitive dependency in a legacy app.","commonSituations":"Long-lived Rails 3/4 apps upgrading cancancan but not the test stack; gems tested across many appraisals where one appraisal still uses RSpec 2.","solutions":["Upgrade to RSpec >= 3 (rspec-rails '~> 3.0' or newer) and re-run bundle install.","If the old RSpec must stay, pin cancancan to a version below 2.0 that still supports it.","Stop requiring cancan/matchers in the legacy setup and test abilities with plain assertions (ability.can?(:read, article).should be_true style) until the upgrade."],"exampleFix":"# before (Gemfile)\ngem 'cancancan'\ngem 'rspec-rails', '~> 2.14'  # Spec constant -> deprecation warning on require 'cancan/matchers'\n\n# after (Gemfile)\ngem 'cancancan'\ngem 'rspec-rails', '~> 6.0'","handlingStrategy":"validation","validationCode":"# spec_helper.rb — fail fast on unsupported RSpec instead of warning\nraise 'CanCanCan matchers need RSpec >= 3' if defined?(Spec) && !defined?(RSpec::Core)\nrequire 'cancan/matchers'","typeGuard":"def modern_rspec?\n  defined?(RSpec::Core) && Gem::Version.new(RSpec::Version::STRING) >= Gem::Version.new('3.0')\nend","tryCatchPattern":null,"preventionTips":["Pin rspec-rails '>= 3' in the Gemfile so Bundler cannot resolve legacy RSpec.","Treat deprecation warnings as CI failures (config.raise_errors_for_deprecations! in rspec 2 or a warning-as-error flag).","Require 'cancan/matchers' only from spec files, never from app initializers.","Run bundle update rspec after upgrading cancancan major versions."],"tags":["rspec","deprecation","version-compatibility","cancancan","ruby"],"backgroundTag":"library-deprecation-warning","analyzedSha":"8c1bf153a3da7b2261d6fa4a5f84eb28e2feb828","analyzedAt":"2026-08-21T20:05:55.000Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}