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
@@ -71,7 +71,7 @@ end
71
71
 
72
72
  gem_spec = Gem::Specification.new do |s|
73
73
  s.name = 'synthesis'
74
- s.version = '0.0.4'
74
+ s.version = '0.0.5'
75
75
  s.platform = Gem::Platform::RUBY
76
76
  s.rubyforge_project = "synthesis"
77
77
  s.summary, s.description = 'A tool for Synthesized Testing'
@@ -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
- return nil if obj.is_a?(Class::AnyInstance)
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
@@ -4,8 +4,7 @@ module Synthesis
4
4
  alias mocha_invoked invoked
5
5
 
6
6
  def invoked(receiver, method, args = [])
7
- return nil if receiver.mocked?
8
- mocha_invoked(receiver, method, args)
7
+ mocha_invoked(receiver, method, args) unless receiver.mocked?
9
8
  end
10
9
  end
11
10
  end
@@ -16,8 +16,6 @@ module Synthesis
16
16
  def record_invocations
17
17
  meta_receiver.extend Recordable
18
18
  meta_receiver.recordable_method @method
19
- rescue NameError => e
20
- log "Failed to record #{@method} on #{@receiver} : #{e.message}"
21
19
  end
22
20
 
23
21
  def ==(other)
@@ -1,17 +1,40 @@
1
1
  module Synthesis
2
2
  module Recordable
3
- def recordable_method(method)
4
- unless method_defined? "__recordable__#{method}".intern
5
- alias_method "__recordable__#{method}".intern, method
6
- class_eval @@recordable_method_def[method]
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 { |method| %(
11
- def #{method}(*args, &block)
12
- MethodInvocationWatcher.invoked(self, "#{method}".intern, args)
13
- send "__recordable__#{method}", *args, &block
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
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-04 00:00:00 +00:00
12
+ date: 2008-02-05 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15