Class: VerifiedDouble::MethodSignatureValue

Inherits:
Object
  • Object
show all
Defined in:
lib/verified_double/method_signature_value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ MethodSignatureValue

Returns a new instance of MethodSignatureValue.



5
6
7
# File 'lib/verified_double/method_signature_value.rb', line 5

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/verified_double/method_signature_value.rb', line 3

def value
  @value
end

Instance Method Details

#accepts?(other) ⇒ Boolean

Returns:



9
10
11
12
13
14
15
# File 'lib/verified_double/method_signature_value.rb', line 9

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

#as_instanceObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/verified_double/method_signature_value.rb', line 17

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

#modified_classObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/verified_double/method_signature_value.rb', line 29

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


41
42
43
# File 'lib/verified_double/method_signature_value.rb', line 41

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