lib/rspec/sleeping_king_studios/matchers/core/construct_matcher.rb
# Checks if the object responds to :new. If so, allocates an instance and
# checks the parameters expected by #initialize against the expected
# parameters, if any.
#
# @param [Object] actual The object to check.
#
# @return [Boolean] True if the object responds to :new and accepts the
#   specified parameters for #initialize; otherwise false.
Checks if the object responds to :new. If so, allocates an instance and
checks the parameters expected by #initialize against the expected
parameters, if any.
Checks if the object responds to : new . If so allocates an instance and checks the parameters expected by #initialize against the expected parameters if any .
def matches? actual
      @actual = actual
      @failing_method_reasons = {}
      unless @actual.respond_to?(:new, @include_all)
        @failing_method_reasons = {
          :does_not_respond_to_new => true
        } 
        return false
      end 
      instance =
        begin; actual.allocate; rescue NoMethodError; nil; end ||
        begin; actual.new;      rescue StandardError; nil; end
      if instance.nil?
        @failing_method_reasons = {
          :unable_to_create_instance => true
        } 
        return false
      end 
      constructor =
        begin; instance.method(:initialize); rescue NameError; nil; end
      unless constructor.is_a?(Method)
        @failing_method_reasons = {
          :constructor_is_not_a_method => true
        } 
        return false
      end 
      return true unless method_signature_expectation?
      unless check_method_signature(constructor)
        @failing_method_reasons = method_signature_expectation.errors
        return false
      end 
      true
    end
def matches? actual @actual = actual @failing_method_reasons = { } unless @actual . respond_to? ( :new , @include_all ) @failing_method_reasons = { :does_not_respond_to_new => true } return false end instance = begin ; actual . allocate ; rescue NoMethodError ; nil ; end || begin ; actual . new ; rescue StandardError ; nil ; end if instance . nil? @failing_method_reasons = { :unable_to_create_instance => true } return false end constructor = begin ; instance . method ( :initialize ) ; rescue NameError ; nil ; end unless constructor . is_a? ( Method ) @failing_method_reasons = { :constructor_is_not_a_method => true } return false end return true unless method_signature_expectation? unless check_method_signature ( constructor ) @failing_method_reasons = method_signature_expectation . errors return false end true end
Checks if the object responds to :new.
Checks if the object responds to : new .
# end hash # unless # end hash # unless # end hash # unless # unless
True if the object responds to :new and accepts the specified parameters for #initialize; otherwise false.
True if the object responds to : new and accepts the specified parameters for #initialize ; otherwise false .
Boolean
actual
<not_specific>
<not_specific>
actual The object to check.
actual The object to check .