synthesis 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/README +20 -1
- data/Rakefile +2 -35
- data/lib/synthesis/expectation_interceptor.rb +25 -19
- data/lib/synthesis/expectation_record_enabled.rb +10 -9
- data/lib/synthesis/util/mock_instance.rb +7 -0
- metadata +3 -2
data/README
CHANGED
@@ -42,7 +42,7 @@ To use with Test::Unit and Mocha, ignoring Array and Hash:
|
|
42
42
|
|
43
43
|
Synthesis::Task.new do |t|
|
44
44
|
t.pattern = 'test/unit/**/*_test.rb'
|
45
|
-
t.ignored =
|
45
|
+
t.ignored = [Array, Hash]
|
46
46
|
end
|
47
47
|
|
48
48
|
To use with RSpec, running all specs in the <tt>spec</tt> directory:
|
@@ -63,6 +63,25 @@ To use with Expectations, redirecting output to a file
|
|
63
63
|
t.out = File.new "synthesis.test.txt", "a"
|
64
64
|
end
|
65
65
|
|
66
|
+
== Utilities
|
67
|
+
|
68
|
+
=== mock_instance
|
69
|
+
|
70
|
+
require "synthesis/util/mock_instance"
|
71
|
+
foo_mock = Foo.mock_instance(arg_one, arg_2)
|
72
|
+
|
73
|
+
This is equivalent, but without calling the real <tt>initialize</tt>, to:
|
74
|
+
|
75
|
+
foo_mock = Foo.new
|
76
|
+
Foo.expects(:new).with(arg_one, arg_two).returns(foo_mock)
|
77
|
+
|
78
|
+
Or, in the case of RSpec, it is equivalent to:
|
79
|
+
|
80
|
+
foo_mock = Foo.new
|
81
|
+
Foo.should_receive(:new).with(arg_one, arg_two).and_return(foo_mock)
|
82
|
+
|
83
|
+
Either <tt>"mocha_standalone"</tt> or <tt>"spec/mocks"</tt> need to be required before using <tt>mock_instance</tt>.
|
84
|
+
|
66
85
|
== Known Issues
|
67
86
|
|
68
87
|
Reporting the location (filename and line number) of tested/untested expectations doesn't work as intended with the Expectations adapter.
|
data/Rakefile
CHANGED
@@ -37,7 +37,7 @@ end
|
|
37
37
|
|
38
38
|
Synthesis::Task.new do |t|
|
39
39
|
t.pattern = 'test_project/mocha/test/*_test.rb'
|
40
|
-
t.ignored =
|
40
|
+
t.ignored = [Array, Hash]
|
41
41
|
# t.out = File.new('synthesis.test.txt', 'a')
|
42
42
|
end
|
43
43
|
|
@@ -56,42 +56,9 @@ task :publish_rdoc do
|
|
56
56
|
Rake::SshDirPublisher.new("gmalamid@rubyforge.org", "/var/www/gforge-projects/synthesis", "doc").upload
|
57
57
|
end
|
58
58
|
|
59
|
-
namespace :svn do
|
60
|
-
task :st do
|
61
|
-
puts %x[svn st]
|
62
|
-
end
|
63
|
-
|
64
|
-
task :up do
|
65
|
-
puts %x[svn up]
|
66
|
-
end
|
67
|
-
|
68
|
-
task :add do
|
69
|
-
%x[svn st].split(/\n/).each do |line|
|
70
|
-
trimmed_line = line.delete('?').lstrip
|
71
|
-
if line[0,1] =~ /\?/
|
72
|
-
%x[svn add #{trimmed_line}]
|
73
|
-
puts %[added #{trimmed_line}]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
task :delete do
|
79
|
-
%x[svn st].split(/\n/).each do |line|
|
80
|
-
trimmed_line = line.delete('!').lstrip
|
81
|
-
if line[0,1] =~ /\!/
|
82
|
-
%x[svn rm #{trimmed_line}]
|
83
|
-
puts %[removed #{trimmed_line}]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
desc "Run before checking in"
|
89
|
-
task :pc => %w[svn:add svn:delete svn:up default svn:st]
|
90
|
-
end
|
91
|
-
|
92
59
|
gem_spec = Gem::Specification.new do |s|
|
93
60
|
s.name = 'synthesis'
|
94
|
-
s.version = '0.0.
|
61
|
+
s.version = '0.0.15'
|
95
62
|
s.platform = Gem::Platform::RUBY
|
96
63
|
s.rubyforge_project = "synthesis"
|
97
64
|
s.summary, s.description = 'A tool for Synthesized Testing'
|
@@ -8,14 +8,19 @@ module Synthesis
|
|
8
8
|
def record_expected_argument_types_on(method_name)
|
9
9
|
@original_with = method_name
|
10
10
|
|
11
|
-
class_eval
|
12
|
-
|
11
|
+
class_eval do
|
12
|
+
alias_method "intercepted_#{method_name}", method_name
|
13
13
|
|
14
|
-
|
14
|
+
define_method(:get_method_name) {method_name}
|
15
|
+
|
16
|
+
def temp_method(*expected_parameters, &matching_block)
|
15
17
|
synthesis_expectation.args = expected_parameters if synthesis_expectation
|
16
|
-
intercepted_#{
|
18
|
+
send("intercepted_#{get_method_name}", *expected_parameters, &matching_block)
|
17
19
|
end
|
18
|
-
|
20
|
+
|
21
|
+
alias_method method_name, :temp_method
|
22
|
+
undef temp_method
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
# Intercept the mock object framework's expectation method for declaring a mocked
|
@@ -23,29 +28,30 @@ module Synthesis
|
|
23
28
|
def record_expected_return_values_on(method_name)
|
24
29
|
@original_returns = method_name
|
25
30
|
|
26
|
-
class_eval
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
mock_expectation = intercepted_#{
|
31
|
+
class_eval do
|
32
|
+
alias_method "intercepted_#{method_name}", method_name
|
33
|
+
|
34
|
+
define_method(method_name) do |*values|
|
35
|
+
mock_expectation = send("intercepted_#{method_name}", *values)
|
31
36
|
synthesis_expectation.add_return_values(*values) if synthesis_expectation
|
32
37
|
mock_expectation
|
33
38
|
end
|
34
|
-
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
42
|
# Restore the original methods ExpectationInterceptor has rewritten and
|
38
43
|
# undefine their intercepted counterparts. Undefine the synthesis_expectation
|
39
44
|
# accessors.
|
40
45
|
def stop_intercepting!
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
with_method, returns_method = @original_with, @original_returns
|
47
|
+
class_eval do
|
48
|
+
alias_method with_method, "intercepted_#{with_method}"
|
49
|
+
alias_method returns_method, "intercepted_#{returns_method}"
|
50
|
+
remove_method "intercepted_#{with_method}"
|
51
|
+
remove_method "intercepted_#{returns_method}"
|
52
|
+
remove_method :synthesis_expectation
|
53
|
+
remove_method :synthesis_expectation=
|
54
|
+
end
|
49
55
|
end
|
50
56
|
|
51
57
|
# Classes extending ExpectationInterceptor will have a synthesis_expectation
|
@@ -8,25 +8,26 @@ module Synthesis
|
|
8
8
|
def record_expectations_on(method_name)
|
9
9
|
@original_expects = method_name
|
10
10
|
|
11
|
-
class_eval
|
12
|
-
|
11
|
+
class_eval do
|
12
|
+
alias_method "intercepted_#{method_name}", method_name
|
13
13
|
|
14
|
-
|
14
|
+
define_method(method_name) do |meth|
|
15
15
|
s_expectation = ExpectationRecord.add_expectation(self, meth, caller[0])
|
16
|
-
m_expectation = intercepted_#{
|
16
|
+
m_expectation = send("intercepted_#{method_name}", meth)
|
17
17
|
m_expectation.synthesis_expectation = s_expectation
|
18
18
|
m_expectation
|
19
19
|
end
|
20
|
-
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
# Restore the original methods ExpectationRecordEnabled has rewritten and
|
24
24
|
# undefine their intercepted counterparts.
|
25
25
|
def stop_recording!
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
method_name = @original_expects
|
27
|
+
class_eval do
|
28
|
+
alias_method method_name, "intercepted_#{method_name}"
|
29
|
+
remove_method "intercepted_#{method_name}"
|
30
|
+
end
|
30
31
|
end
|
31
32
|
end
|
32
33
|
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.15
|
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-05-
|
12
|
+
date: 2008-05-25 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/synthesis/task.rb
|
44
44
|
- lib/synthesis/util/mock_instance/mocha.rb
|
45
45
|
- lib/synthesis/util/mock_instance/rspec.rb
|
46
|
+
- lib/synthesis/util/mock_instance.rb
|
46
47
|
- lib/synthesis.rb
|
47
48
|
- test/synthesis/adapter/mocha/expectation_record_test.rb
|
48
49
|
- test/synthesis/adapter/mocha/helper.rb
|