synthesis 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
@@ -5,8 +5,7 @@ module Synthesis
|
|
5
5
|
|
6
6
|
def add_expectation(obj, meth, track, args = [])
|
7
7
|
# Ignone things like "foo = mock"
|
8
|
-
|
9
|
-
add_mocha_expectation(obj, meth, track, args)
|
8
|
+
add_mocha_expectation(obj, meth, track, args) unless obj.is_a?(Class::AnyInstance)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
data/lib/synthesis/recordable.rb
CHANGED
@@ -1,17 +1,40 @@
|
|
1
1
|
module Synthesis
|
2
2
|
module Recordable
|
3
|
-
def recordable_method(
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def recordable_method(meth)
|
4
|
+
if method_defined? meth
|
5
|
+
defined_recordable_method meth
|
6
|
+
else
|
7
|
+
magic_recordable_method meth
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def defined_recordable_method(meth)
|
14
|
+
unless method_defined? "__recordable__#{meth}".intern
|
15
|
+
alias_method "__recordable__#{meth}".intern, meth
|
16
|
+
class_eval @@recordable_method_def[meth]
|
7
17
|
end
|
8
18
|
end
|
9
19
|
|
10
|
-
@@recordable_method_def = proc { |
|
11
|
-
def #{
|
12
|
-
MethodInvocationWatcher.invoked(self, "#{
|
13
|
-
send "__recordable__#{
|
20
|
+
@@recordable_method_def = proc { |meth| %(
|
21
|
+
def #{meth}(*args, &block)
|
22
|
+
MethodInvocationWatcher.invoked(self, "#{meth}".intern, args)
|
23
|
+
send "__recordable__#{meth}", *args, &block
|
14
24
|
end
|
15
25
|
)}
|
26
|
+
|
27
|
+
def magic_recordable_method(meth)
|
28
|
+
class_eval @@recordable_magic_method_def[meth]
|
29
|
+
end
|
30
|
+
|
31
|
+
@@recordable_magic_method_def = proc { |meth| %(
|
32
|
+
def #{meth}(*args)
|
33
|
+
MethodInvocationWatcher.invoked(self, "#{meth}".intern, args)
|
34
|
+
method_missing(:#{meth}, *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def __recordable__#{meth}() raise "Don't ever call me" end
|
38
|
+
)}
|
16
39
|
end
|
17
40
|
end
|
@@ -26,5 +26,42 @@ module Synthesis
|
|
26
26
|
foo.expects(:alias_method).never
|
27
27
|
foo.recordable_method(:b)
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_defines_non_existent_method
|
31
|
+
foo = Class.new
|
32
|
+
foo.extend Recordable
|
33
|
+
foo.recordable_method(:bar)
|
34
|
+
assert_respond_to(foo.new, :bar)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_defines_non_existent_method_recordable_placeholder_method
|
38
|
+
foo = Class.new
|
39
|
+
foo.extend Recordable
|
40
|
+
foo.recordable_method(:bar)
|
41
|
+
assert_respond_to(foo.new, :__recordable__bar)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_non_existed_method_placeholder_raises
|
45
|
+
foo = Class.new
|
46
|
+
foo.extend Recordable
|
47
|
+
foo.recordable_method(:bar)
|
48
|
+
assert_raise(RuntimeError) { foo.new.__recordable__bar }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_does_not_redefine_already_defined_magic_method
|
52
|
+
foo = Class.new
|
53
|
+
foo.extend Recordable
|
54
|
+
foo.recordable_method(:b)
|
55
|
+
foo.expects(:alias_method).never
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_records_magic_method_invocation
|
59
|
+
foo = Class.new {def method_missing(meth, *args) :magic! end}
|
60
|
+
foo.extend Recordable
|
61
|
+
foo.recordable_method(:b)
|
62
|
+
bar = foo.new
|
63
|
+
MethodInvocationWatcher.expects(:invoked).with(bar, :b, [])
|
64
|
+
bar.b
|
65
|
+
end
|
29
66
|
end
|
30
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synthesis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Caborn, George Malamidis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-05 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|