Module: MacSpec::MockingFramework::ObjectExtension

Defined in:
lib/mac_spec/mocking_framework/extensions/object_extension.rb

Instance Method Summary collapse

Instance Method Details

#__macspec__reset!Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mac_spec/mocking_framework/extensions/object_extension.rb', line 56

def __macspec__reset!
  @__macspec__message_expectations && @__macspec__message_expectations.each do |me|
    if respond_to?(me.unique_alias) && respond_to?(me.msg)
      (class<<self;self;end).instance_eval do 
        undef_method me.msg
        alias_method me.msg, me.unique_alias
        undef_method me.unique_alias
      end
    else
    end
  end
  @__macspec__message_expectations = nil
end

#__macspec__verifyObject



46
47
48
49
50
51
52
53
54
# File 'lib/mac_spec/mocking_framework/extensions/object_extension.rb', line 46

def __macspec__verify
  begin
    @__macspec__message_expectations && @__macspec__message_expectations.each do |me|
      me && me.verify
    end
  ensure
    __macspec__reset!
  end
end

#should_not_receive(msg) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mac_spec/mocking_framework/extensions/object_extension.rb', line 17

def should_not_receive(msg)
  @__macspec__message_expectations ||= []
  options = {
    :receiver => self,
    :positive => false,
    :msg      => msg,
    :stub     => false
  }
  message_expectation = MacSpec::MockingFramework::MessageExpectation.new(options)
  @__macspec__message_expectations << message_expectation
  return message_expectation
end

#should_receive(msg) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mac_spec/mocking_framework/extensions/object_extension.rb', line 4

def should_receive(msg)
  @__macspec__message_expectations ||= []
  options = {
    :receiver => self,
    :positive => true,
    :msg      => msg,
    :stub     => false
  }
  message_expectation = MacSpec::MockingFramework::MessageExpectation.new(options)
  @__macspec__message_expectations << message_expectation
  return message_expectation
end

#stub!(hash) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mac_spec/mocking_framework/extensions/object_extension.rb', line 30

def stub!(hash)
  hash = {hash => nil} unless Hash === hash
  @__macspec__message_expectations ||= []
  hash.each do |meth_to_stub, ret_val|
    options = {
      :receiver          => self,
      :positive          => true,
      :msg               => meth_to_stub,
      :stub              => true,
      :stub_return_value => ret_val
    }
    message_expectation = MacSpec::MockingFramework::MessageExpectation.new(options)
    @__macspec__message_expectations << message_expectation
  end
end