Class: Sequent::Core::Helpers::MessageMatchers::ArgumentCoercer

Inherits:
Object
  • Object
show all
Defined in:
lib/sequent/core/helpers/message_matchers/argument_coercer.rb

Class Method Summary collapse

Class Method Details

.coerce_argument(arg) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/sequent/core/helpers/message_matchers/argument_coercer.rb', line 9

def coerce_argument(arg)
  fail ArgumentError, 'Cannot coerce nil argument' if arg.nil?

  return MessageMatchers::InstanceOf.new(arg) if [Class, Module].include?(arg.class)
  return arg if arg.respond_to?(:matches_message?)

  fail ArgumentError,
       "Can't coerce argument '#{arg}'; " \
       'must be either a Class, Module or message matcher (respond to :matches_message?)'
end