thoughtbot/shoulda-matchers · error · ArgumentError

Invalid counter_cache option

Error message

Invalid counter_cache option

What it means

Error "Invalid counter_cache option" thrown in thoughtbot/shoulda-matchers.

Source

Thrown at lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb:64

              )
            end
          end

          def option_verifier
            @_option_verifier ||= OptionVerifier.new(subject)
          end

          def normalize_value
            if Rails::VERSION::STRING >= '7.2'
              case counter_cache
              when true
                { active: true, column: nil }
              when String, Symbol
                { active: true, column: counter_cache.to_s }
              when Hash
                { active: true, column: nil }.merge!(counter_cache)
              else
                raise ArgumentError, 'Invalid counter_cache option'
              end
            else
              counter_cache
            end
          end
        end
      end
    end
  end
end

View on GitHub (pinned to 79cdfbc326)

When it happens

Trigger: Thrown at lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb:64 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of thoughtbot/shoulda-matchers@79cdfbc326 (2026-08-23). Data as JSON: /api/errors/c4259ad9ce802f69. Report an issue: GitHub.