/
method_double.tcl
67 lines (56 loc) · 2.14 KB
/
method_double.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace eval Spec::Mocks::nx {
nx::Class create MethodDouble -superclass Abstract::MessageDouble {
:property object:required
:property proxy:required
:variable stashed false
:variable stashed_definition
:public method configure_message { } {
[::Spec::Mocks space] add ${:object}
if { !${:stashed} } {
:stash_original_method
:define_proxy_method
}
}
:public method stash_original_method {} {
set :stashed true
set :stashed_definition [:original_method_definition]
}
:public method reset {} {
:restore_original_method
next
}
:public method original_method_definition {} {
${:object} info method definition ${:message_name}
}
:public method visibility {} {
if { [${:object} info class] == "::Spec::Mocks::nx::Mock" } {
return "public"
} else {
set definition [${:object} info method definition ${:message_name}]
if { $definition == "" } {
set definition [[${:object} info class] info method definition ${:message_name}]
}
if { $definition != "" } {
return "[lindex $definition 1][expr {[${:object} info class] == "::nx::Class" ? " class" : ""}]"
} else {
return "public[expr {[${:object} info class] == "::nx::Class" ? " class" : ""}]"
}
}
}
:public method define_proxy_method {} {
${:object} {*}[:visibility] method ${:message_name} { args } "
\[:__mock_proxy] message_received {${:message_name}} {*}\$args
"
}
:public method undefine_proxy_method {} {
${:object} {*}[:visibility] method ${:message_name} {} {}
}
:public method restore_original_method {} {
if { ${:stashed} } {
:undefine_proxy_method
eval ${:stashed_definition}
set :stashed false
}
}
}
}