yuku-t/duck_testing

View on GitHub
lib/duck_testing/reporter/raise_error.rb

Summary

Maintainability
A
0 mins
Test Coverage
require "duck_testing/reporter/base"

module DuckTesting
  module Reporter
    class RaiseError < Base
      # @note Override {DuckTesting::Reporter::Base#report}.
      def report
        fail ContractViolationError, failure_message
      end

      private

      def failure_message
        %(#{message_header}
            Expected: #{violation.expected}
            Actual: #{violation.param.inspect})
      end

      def message_header
        if violation.param?
          "Contract violation for argument of #{violation.method_expr}"
        elsif violation.return?
          "Contract violation for return value from #{violation.method_expr}"
        else
          fail NotImplementedError
        end
      end
    end
  end
end