Class: Synthesis::Expectation::Expectation

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/synthesis/expectation.rb

Direct Known Subclasses

Instance, NilExpectation, Singleton

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#silence!, #speak!

Constructor Details

#initialize(receiver, method, track, args, return_values) ⇒ Expectation

Returns a new instance of Expectation.



13
14
15
16
# File 'lib/synthesis/expectation.rb', line 13

def initialize(receiver, method, track, args, return_values)
  @receiver, @method, @track, @args = receiver, method.to_sym, track, args
  @return_values = return_values
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



11
12
13
# File 'lib/synthesis/expectation.rb', line 11

def args
  @args
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/synthesis/expectation.rb', line 9

def method
  @method
end

#receiverObject (readonly)

Returns the value of attribute receiver.



9
10
11
# File 'lib/synthesis/expectation.rb', line 9

def receiver
  @receiver
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/synthesis/expectation.rb', line 48

def ==(other)
  eql?(other)
end

#add_return_values(*vals) ⇒ Object



68
69
70
71
# File 'lib/synthesis/expectation.rb', line 68

def add_return_values(*vals)
  @return_values_defined = true
  @return_values += vals
end

#add_test_subject(test_subject) ⇒ Object



23
24
25
# File 'lib/synthesis/expectation.rb', line 23

def add_test_subject(test_subject)
  (@callers ||= []) << test_subject
end

#arg_typesObject



60
61
62
# File 'lib/synthesis/expectation.rb', line 60

def arg_types
  args.map { |arg| arg.class }
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/synthesis/expectation.rb', line 44

def eql?(other)
  ExpectationMatcher.new(self, other).match?
end

#explodeObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/synthesis/expectation.rb', line 31

def explode
  if @return_values.size > 1
    @return_values.map do |v|
      expectation = self.class.new(@receiver, @method, @track, @args, [])
      expectation.add_test_subject(@callers.shift)
      expectation.add_return_values(v)
      expectation
    end
  else
    self
  end
end

#invoked!Object



56
57
58
# File 'lib/synthesis/expectation.rb', line 56

def invoked!
  @invoked = true
end

#invoked?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/synthesis/expectation.rb', line 52

def invoked?
  @invoked
end

#record_invocationsObject



18
19
20
21
# File 'lib/synthesis/expectation.rb', line 18

def record_invocations
  meta_receiver.extend(Recordable)
  meta_receiver.recordable_method(@method)
end

#return_value_typeObject



64
65
66
# File 'lib/synthesis/expectation.rb', line 64

def return_value_type
  @return_values.size == 1 ? @return_values[0].class : nil
end

#return_values_defined?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/synthesis/expectation.rb', line 73

def return_values_defined?
  @return_values_defined
end

#test_subjectObject



27
28
29
# File 'lib/synthesis/expectation.rb', line 27

def test_subject
  @callers[0]
end