class DuckTesting::Tester

Attributes

call_data[R]

Public Class Methods

new(receiver, method_name) click to toggle source

@param receiver [Object] the receiver object. @param method_name [String] the invoked method’s name.

# File lib/duck_testing/tester.rb, line 7
def initialize(receiver, method_name)
  @call_data = MethodCallData.new(receiver, method_name)
end

Public Instance Methods

match?(param, expected_types) click to toggle source

@param param [Object] @param expected_types [Array<DuckTesting::Type::Base>] @return [Boolean]

# File lib/duck_testing/tester.rb, line 28
def match?(param, expected_types)
  expected_types.any? do |type|
    type.match?(param)
  end
end
test_param(param, expected_types) click to toggle source

@param param [Object] @param expected_types [Array<DuckTesting::Type::Base>]

# File lib/duck_testing/tester.rb, line 13
def test_param(param, expected_types)
  test(param, expected_types, :param)
end
test_return(param, expected_types) click to toggle source

@param param [Object] @param expected_types [Array<DuckTesting::Type::Base>] @return [Object]

# File lib/duck_testing/tester.rb, line 20
def test_return(param, expected_types)
  test(param, expected_types, :return)
  param
end

Private Instance Methods

test(param, expected_types, type) click to toggle source

@param param [Object] @param expected_types [Array<DuckTesting::Type::Base>] @param type [Symbol] ‘:param` or `:return`

# File lib/duck_testing/tester.rb, line 39
def test(param, expected_types, type)
  return if match?(param, expected_types) || expected_types.empty?
  violation = Violation.new(
    call_data: call_data,
    param: param,
    expected_types: expected_types,
    param_or_return: type
  )
  Reporter::RaiseError.new(violation).report
end