thoughtbot/shoulda-matchers · error · DelegateObjectNotSpecified

Delegation needs a target. Use the #to method to define one,

Error message

Delegation needs a target. Use the #to method to define one, e.g. `post_office.should delegate(:deliver_mail).to(:mailman)`

What it means

Error "Delegation needs a target. Use the #to method to define one, e.g. `post_office.should delegate(:deliver_mail).to(:mailman)`" thrown in thoughtbot/shoulda-matchers.

Source

Thrown at lib/shoulda/matchers/independent/delegate_method_matcher.rb:422

            call.args == delegated_arguments
          end
        end

        def subject_has_delegating_method?
          if expects_private_delegation?
            !subject.respond_to?(delegating_method) && subject.respond_to?(delegating_method, true)
          else
            subject.respond_to?(delegating_method)
          end
        end

        def subject_has_delegate_object_reader_method?
          subject.respond_to?(delegate_object_reader_method, true)
        end

        def ensure_delegate_object_has_been_specified!
          if delegate_object_reader_method.to_s.empty?
            raise DelegateObjectNotSpecified
          end
        end

        def subject_delegates_to_delegate_object_correctly?
          if expects_private_delegation?
            privately_call_delegating_method_with_delegate_method_returning(delegate_object)
          else
            call_delegating_method_with_delegate_method_returning(delegate_object)
          end

          if delegated_arguments.any?
            delegate_object_received_call_with_delegated_arguments?
          else
            delegate_object_received_call?
          end
        end

        def subject_handles_nil_delegate_object?

View on GitHub (pinned to 79cdfbc326)

When it happens

Trigger: Thrown at lib/shoulda/matchers/independent/delegate_method_matcher.rb:422 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/d2650394c30d95ee. Report an issue: GitHub.