Sha256: 9c5162807fc639313baa7cb414cfa8cb58b3c2e4abf69a3267463dd6dab21f7e

Contents?: true

Size: 967 Bytes

Versions: 1

Compression:

Stored size: 967 Bytes

Contents

module VerifiedDouble
  class MethodSignatureValue
    attr_reader :value

    def initialize(value)
      @value = value
    end

    def accepts?(other)
      if self.value.is_a?(Class) || ! other.value.is_a?(Class)
        self.value == other.value
      else
        self.modified_class.ancestors.include?(other.value)
      end
    end

    def as_instance
      if self.value.is_a?(Class)
        begin
          value.new
        rescue NoMethodError
          Object.new
        end
      else
        self.value
      end
    end

    def modified_class
      if value.is_a?(RSpec::Mocks::Mock)
        value.instance_variable_get('@name').constantize
      elsif value.is_a?(VerifiedDouble::RecordingDouble)
        value.class_name.constantize
      elsif value == true or value == false
        VerifiedDouble::Boolean
      else
        value.class
      end
    end

    def recommended_value
      self.class.new(self.modified_class)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
verified_double-0.1.1 lib/verified_double/method_signature_value.rb