synthesis 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +9 -9
- data/lib/synthesis/adapter.rb +1 -1
- data/lib/synthesis/adapter/expectations.rb +1 -1
- data/lib/synthesis/adapter/mocha.rb +1 -1
- data/lib/synthesis/adapter/rspec.rb +1 -1
- data/lib/synthesis/expectation.rb +7 -2
- data/lib/synthesis/expectation_interceptor.rb +1 -1
- data/lib/synthesis/expectation_record.rb +1 -1
- data/test/synthesis/expectation_test.rb +26 -5
- data/test_project/mocha/test/data_brander_test.rb +14 -0
- data/test_project/mocha/test/storage_test.rb +8 -0
- data/test_project/rspec/data_brander_spec.rb +14 -0
- data/test_project/rspec/storage_spec.rb +8 -0
- data/test_project/test_project.rb +12 -0
- metadata +2 -2
data/Rakefile
CHANGED
@@ -25,22 +25,22 @@ Rake::TestTask.new('test:spec') do |t|
|
|
25
25
|
t.pattern = 'test/synthesis/adapter/rspec/*_test.rb'
|
26
26
|
end
|
27
27
|
|
28
|
-
Synthesis::Task.new
|
28
|
+
Synthesis::Task.new do |t|
|
29
|
+
t.pattern = 'test_project/mocha/test/*_test.rb'
|
30
|
+
t.ignored = [Array, Hash]
|
31
|
+
# t.out = File.new('synthesis.test.txt', 'a')
|
32
|
+
end
|
33
|
+
|
34
|
+
Synthesis::Task.new('synthesis:expectations') do |t|
|
29
35
|
t.adapter = :expectations
|
30
36
|
t.pattern = 'test_project/expectations/test/*_test.rb'
|
31
37
|
end
|
32
38
|
|
33
|
-
Synthesis::Task.new('synthesis:
|
39
|
+
Synthesis::Task.new('synthesis:spec') do |t|
|
34
40
|
t.adapter = :rspec
|
35
41
|
t.pattern = 'test_project/rspec/*_spec.rb'
|
36
42
|
end
|
37
43
|
|
38
|
-
Synthesis::Task.new do |t|
|
39
|
-
t.pattern = 'test_project/mocha/test/*_test.rb'
|
40
|
-
t.ignored = [Array, Hash]
|
41
|
-
# t.out = File.new('synthesis.test.txt', 'a')
|
42
|
-
end
|
43
|
-
|
44
44
|
desc 'Generate RDoc'
|
45
45
|
Rake::RDocTask.new do |task|
|
46
46
|
task.main = 'README'
|
@@ -58,7 +58,7 @@ end
|
|
58
58
|
|
59
59
|
gem_spec = Gem::Specification.new do |s|
|
60
60
|
s.name = 'synthesis'
|
61
|
-
s.version = '0.1.
|
61
|
+
s.version = '0.1.1'
|
62
62
|
s.platform = Gem::Platform::RUBY
|
63
63
|
s.rubyforge_project = "synthesis"
|
64
64
|
s.summary, s.description = 'A tool for Synthesized Testing'
|
data/lib/synthesis/adapter.rb
CHANGED
@@ -15,7 +15,7 @@ module Synthesis
|
|
15
15
|
def fail_unless(&block)
|
16
16
|
log "Collecting expectations..."
|
17
17
|
collect_expectations
|
18
|
-
Dir[
|
18
|
+
Dir[*@pattern].each { |t| require t }
|
19
19
|
exit -1 unless yield
|
20
20
|
log "Verifying expectation invocations..."
|
21
21
|
stop_collecting_expectations
|
@@ -15,7 +15,7 @@ module Synthesis
|
|
15
15
|
Object.extend(ExpectationRecordEnabled)
|
16
16
|
Object.record_expectations_on(:expects)
|
17
17
|
Mocha::Expectation.extend(ExpectationInterceptor)
|
18
|
-
Mocha::Expectation.
|
18
|
+
Mocha::Expectation.record_expected_arguments_on(:with)
|
19
19
|
Mocha::Expectation.record_expected_return_values_on(:returns)
|
20
20
|
Mocha::Expectation.record_expected_return_values_on(:raises)
|
21
21
|
end
|
@@ -16,7 +16,7 @@ module Synthesis
|
|
16
16
|
Object.extend(ExpectationRecordEnabled)
|
17
17
|
Object.record_expectations_on(:expects)
|
18
18
|
Mocha::Expectation.extend(ExpectationInterceptor)
|
19
|
-
Mocha::Expectation.
|
19
|
+
Mocha::Expectation.record_expected_arguments_on(:with)
|
20
20
|
Mocha::Expectation.record_expected_return_values_on(:returns)
|
21
21
|
Mocha::Expectation.record_expected_return_values_on(:raises)
|
22
22
|
end
|
@@ -20,7 +20,7 @@ module Synthesis
|
|
20
20
|
Spec::Mocks::Methods.extend(ExpectationRecordEnabled)
|
21
21
|
Spec::Mocks::Methods.record_expectations_on(:should_receive)
|
22
22
|
Spec::Mocks::MessageExpectation.extend(ExpectationInterceptor)
|
23
|
-
Spec::Mocks::MessageExpectation.
|
23
|
+
Spec::Mocks::MessageExpectation.record_expected_arguments_on(:with)
|
24
24
|
Spec::Mocks::MessageExpectation.record_expected_return_values_on(:and_return)
|
25
25
|
Spec::Mocks::MessageExpectation.record_expected_return_values_on(:and_raise)
|
26
26
|
end
|
@@ -6,7 +6,8 @@ module Synthesis
|
|
6
6
|
|
7
7
|
class Expectation
|
8
8
|
include Logging
|
9
|
-
attr_reader :receiver, :method
|
9
|
+
attr_reader :receiver, :method, :return_values
|
10
|
+
protected :return_values
|
10
11
|
attr_accessor :args
|
11
12
|
|
12
13
|
def initialize(receiver, method, track, args, return_values)
|
@@ -39,6 +40,10 @@ module Synthesis
|
|
39
40
|
eql?(other)
|
40
41
|
end
|
41
42
|
|
43
|
+
def <=>(other)
|
44
|
+
@return_values.size <=> other.return_values.size
|
45
|
+
end
|
46
|
+
|
42
47
|
def invoked?
|
43
48
|
@invoked
|
44
49
|
end
|
@@ -52,7 +57,7 @@ module Synthesis
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def return_value_type
|
55
|
-
@return_values
|
60
|
+
@return_values.size == 1 ? @return_values[0].class : nil
|
56
61
|
end
|
57
62
|
|
58
63
|
def add_return_values(*vals)
|
@@ -5,7 +5,7 @@ module Synthesis
|
|
5
5
|
module ExpectationInterceptor
|
6
6
|
# Intercept the mock object framework's expectation method for declaring a mocked
|
7
7
|
# method's arguments so that Synthesis can record them.
|
8
|
-
def
|
8
|
+
def record_expected_arguments_on(method_name)
|
9
9
|
(@original_methods ||= []) << method_name
|
10
10
|
|
11
11
|
class_eval do
|
@@ -51,12 +51,30 @@ module Synthesis
|
|
51
51
|
expectation = Expectation.new(String.new, :new, :track, [:sym, "str"], [])
|
52
52
|
assert_equal([Symbol, String], expectation.arg_types)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def test_return_value_type
|
56
|
-
expectation = Expectation.new(String
|
56
|
+
expectation = Expectation.new(String, :new, :track)
|
57
|
+
expectation.add_return_values(:sym)
|
57
58
|
assert_equal(Symbol, expectation.return_value_type)
|
58
59
|
end
|
59
60
|
|
61
|
+
def test_true_class_return_value_type
|
62
|
+
expectation = Expectation.new(String, :new, :track)
|
63
|
+
expectation.add_return_values(true)
|
64
|
+
assert_equal(TrueClass, expectation.return_value_type)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_false_class_return_value_type
|
68
|
+
expectation = Expectation.new(String, :new, :track)
|
69
|
+
expectation.add_return_values(false)
|
70
|
+
assert_equal(FalseClass, expectation.return_value_type)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_returns_nil_return_value_type_when_no_return_values
|
74
|
+
expectation = Expectation.new(String, :new, :track)
|
75
|
+
assert_nil(expectation.return_value_type)
|
76
|
+
end
|
77
|
+
|
60
78
|
def test_adds_return_value
|
61
79
|
expectation = Expectation.new(String.new, :new, :track, [], [:sym])
|
62
80
|
expectation.add_return_values("str")
|
@@ -91,9 +109,12 @@ module Synthesis
|
|
91
109
|
assert_equal(expectation, expectation.explode)
|
92
110
|
end
|
93
111
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
112
|
+
def test_expectation_sorting
|
113
|
+
light = Expectation.new(Object.new, :bar, :track, [])
|
114
|
+
heavy = Expectation.new(Object.new, :foo, :track, [], [:retval])
|
115
|
+
sorted = [light, heavy].sort.reverse
|
116
|
+
assert_equal(heavy, sorted[0])
|
117
|
+
assert_equal(light, sorted[1])
|
97
118
|
end
|
98
119
|
end
|
99
120
|
end
|
@@ -19,4 +19,18 @@ class DataBranderTest < Test::Unit::TestCase
|
|
19
19
|
storage.expects(:ouch!).raises(Problem.new)
|
20
20
|
assert_raise(Problem) { DataBrander.new(storage).dont_do_this }
|
21
21
|
end
|
22
|
+
|
23
|
+
def test_is_ok
|
24
|
+
storage = Storage.new("")
|
25
|
+
storage.expects(:ok_or_problem).with(:ok).returns(:ok)
|
26
|
+
DataBrander.new(storage).ok
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_does_not_rescue_problem_on_not_ok
|
30
|
+
assert_raise(Problem) do
|
31
|
+
storage = Storage.new("")
|
32
|
+
storage.expects(:ok_or_problem).with(:not_ok).raises(Problem.new)
|
33
|
+
DataBrander.new(storage).not_ok
|
34
|
+
end
|
35
|
+
end
|
22
36
|
end
|
@@ -13,4 +13,12 @@ class StorageTest < Test::Unit::TestCase
|
|
13
13
|
def test_ouch_raises_problem
|
14
14
|
assert_raise(Problem) { Storage.new("").ouch! }
|
15
15
|
end
|
16
|
+
|
17
|
+
def test_ok_or_problem_returns_ok_when_given_ok
|
18
|
+
assert_equal(:ok, Storage.new("").ok_or_problem(:ok))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_ok_raises_problem_when_not_given_ok
|
22
|
+
assert_raise(Problem) { Storage.new("").ok_or_problem(:not_ok) }
|
23
|
+
end
|
16
24
|
end
|
@@ -19,4 +19,18 @@ describe DataBrander do
|
|
19
19
|
storage.should_receive(:ouch!).and_raise(Problem.new)
|
20
20
|
proc {DataBrander.new(storage).dont_do_this}.should raise_error(Problem)
|
21
21
|
end
|
22
|
+
|
23
|
+
it "should return :ok when given :ok" do
|
24
|
+
storage = Storage.new("")
|
25
|
+
storage.should_receive(:ok_or_problem).with(:ok).and_return(:ok)
|
26
|
+
DataBrander.new(storage).ok
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not rescue problem on not ok" do
|
30
|
+
proc do
|
31
|
+
storage = Storage.new("")
|
32
|
+
storage.should_receive(:ok_or_problem).with(:not_ok).and_raise(Problem.new)
|
33
|
+
DataBrander.new(storage).not_ok
|
34
|
+
end.should raise_error(Problem)
|
35
|
+
end
|
22
36
|
end
|
@@ -14,4 +14,12 @@ describe Storage do
|
|
14
14
|
it "should raise problem on ouch!" do
|
15
15
|
proc { Storage.new("").ouch! }.should raise_error(Problem)
|
16
16
|
end
|
17
|
+
|
18
|
+
it "should return :ok when given :ok" do
|
19
|
+
Storage.new("").ok_or_problem(:ok).should == :ok
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise problem when not give :ok" do
|
23
|
+
proc { Storage.new("").ok_or_problem(:not_ok) }.should raise_error(Problem)
|
24
|
+
end
|
17
25
|
end
|
@@ -12,6 +12,14 @@ class DataBrander
|
|
12
12
|
def dont_do_this
|
13
13
|
@storage.ouch!
|
14
14
|
end
|
15
|
+
|
16
|
+
def ok
|
17
|
+
@storage.ok_or_problem(:ok)
|
18
|
+
end
|
19
|
+
|
20
|
+
def not_ok
|
21
|
+
@storage.ok_or_problem(:not_ok)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
class Storage
|
@@ -26,6 +34,10 @@ class Storage
|
|
26
34
|
def ouch!
|
27
35
|
raise Problem
|
28
36
|
end
|
37
|
+
|
38
|
+
def ok_or_problem(ok)
|
39
|
+
ok == :ok ? ok : raise(Problem)
|
40
|
+
end
|
29
41
|
end
|
30
42
|
|
31
43
|
class Problem < Exception;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.1.
|
4
|
+
version: 0.1.1
|
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-
|
12
|
+
date: 2008-06-04 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|