class Shoulda::Matchers::Independent::DelegateMethodMatcher

def subject_handles_nil_delegate_object?

def subject_handles_nil_delegate_object?
  @subject_handled_nil_delegate_object =
    if expects_to_allow_nil_delegate_object?
      begin
        call_delegating_method_with_delegate_method_returning(nil)
        true
      rescue Module::DelegationError
        false
      rescue NoMethodError => e
        if e.message =~ /undefined method [`']#{delegate_method}[`'] for nil/
          false
        else
          raise e
        end
      end
    else
      true
    end
end