synthesis 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -91,15 +91,15 @@ end
91
91
 
92
92
  gem_spec = Gem::Specification.new do |s|
93
93
  s.name = 'synthesis'
94
- s.version = '0.0.10'
94
+ s.version = '0.0.11'
95
95
  s.platform = Gem::Platform::RUBY
96
96
  s.rubyforge_project = "synthesis"
97
97
  s.summary, s.description = 'A tool for Synthesized Testing'
98
- s.author = 'Stuart Caborn, George Malamidis'
98
+ s.authors = 'Stuart Caborn, George Malamidis'
99
99
  s.email = 'george@nutrun.com'
100
100
  s.homepage = 'http://synthesis.rubyforge.org'
101
101
  s.has_rdoc = true
102
- s.rdoc_options += ['--quiet', '--title', 'Queueue', '--main', 'README', '--inline-source']
102
+ s.rdoc_options += ['--quiet', '--title', 'Synthesis', '--main', 'README', '--inline-source']
103
103
  s.extra_rdoc_files = ['README', 'COPYING']
104
104
  excluded = FileList['etc/*']
105
105
  # s.test_files = FileList['test/**/*_test.rb']
@@ -10,6 +10,7 @@ module Synthesis
10
10
  rspec_options.files.clear
11
11
  fail_unless do
12
12
  rspec_options.instance_variable_set(:@formatters, nil)
13
+ # rspec_options.instance_variable_set(:@format_options, [["profile", STDOUT]])
13
14
  rspec_options.run_examples
14
15
  end
15
16
  end
@@ -19,6 +19,18 @@ module Synthesis
19
19
  meta_receiver.recordable_method(@method)
20
20
  end
21
21
 
22
+ def explode
23
+ if @return_values.size > 1
24
+ @return_values.map do |v|
25
+ expectation = self.class.new(@receiver, @method, @track, @args, [])
26
+ expectation.add_return_values(v)
27
+ expectation
28
+ end
29
+ else
30
+ self
31
+ end
32
+ end
33
+
22
34
  def eql?(other)
23
35
  ExpectationMatcher.new(self, other).match?
24
36
  end
@@ -4,7 +4,7 @@ module Synthesis
4
4
  include Logging
5
5
 
6
6
  def add_expectation(receiver, method, track, args = [])
7
- unless ignore? receiver
7
+ unless ignore?(receiver)
8
8
  expectation = Expectation.new(receiver, method, track, args)
9
9
  expectations << expectation
10
10
  expectation
@@ -12,16 +12,16 @@ module Synthesis
12
12
  end
13
13
 
14
14
  def ignore(*args)
15
- ignored.merge args
15
+ ignored.merge(args)
16
16
  end
17
17
 
18
18
  def expectations
19
- # Using an Array instead of a Set because the +Expectation+ instance is not complete when first added
19
+ # Using an Array instead of a Set because the +Expectation+ instance
20
+ # is not complete when first added. A Set would result to possible duplicates.
20
21
  # obj.expects(:method).with(:args)
21
22
  # the +Expectation+ will be added when obj.expects(:method) is called
22
23
  # the +Expectation+ arguments will be added when .with(:args) is called
23
24
  @expectations ||= []
24
- @expectations.uniq!
25
25
  @expectations
26
26
  end
27
27
 
@@ -30,11 +30,15 @@ module Synthesis
30
30
  end
31
31
 
32
32
  def [](matcher)
33
- # Using a hash when recording invocations for improving performance
33
+ # Using a hash when for faster look up of expectations
34
+ # when recording invocations
34
35
  expectations_hash[matcher] || Expectation::NilExpectation.new
35
36
  end
36
37
 
37
38
  def record_invocations
39
+ expectations.map! { |e| e.explode }
40
+ expectations.flatten!
41
+ expectations.uniq!
38
42
  expectations.each { |e| e.record_invocations }
39
43
  end
40
44
 
@@ -47,5 +47,20 @@ module Synthesis
47
47
  actual.add_return_values(:return_val)
48
48
  assert_equal(expected, actual)
49
49
  end
50
+
51
+ def test_uniqs_expectations_before_recording_invocations
52
+ ExpectationRecord.add_expectation(Hash, :foo, :track)
53
+ ExpectationRecord.add_expectation(Hash, :foo, :track)
54
+ assert_equal(2, ExpectationRecord.expectations.size)
55
+ ExpectationRecord.record_invocations
56
+ assert_equal(1, ExpectationRecord.expectations.size)
57
+ end
58
+
59
+ def test_flattens_expectations_before_recording_invocations
60
+ expectation = ExpectationRecord.add_expectation(Hash, :foo, :track)
61
+ expectation.add_return_values(1, "str", "sym")
62
+ ExpectationRecord.record_invocations
63
+ ExpectationRecord.expectations.each { |val| assert(!val.is_a?(Array)) }
64
+ end
50
65
  end
51
66
  end
@@ -74,5 +74,21 @@ module Synthesis
74
74
  expectation = Expectation.new(String.new, :new, :track, [], [:sym])
75
75
  assert(!expectation.return_values_defined?)
76
76
  end
77
+
78
+ def test_explodes_to_new_expectations_for_each_return_value
79
+ expectation = Expectation.new(String, :new, :track, [])
80
+ expectation.add_return_values(:sym, "str")
81
+ expected = [
82
+ Expectation.new(String, :new, :track, [], [:sym]),
83
+ Expectation.new(String, :new, :track, [], ["str"])
84
+ ]
85
+ assert_equal(expected, expectation.explode)
86
+ end
87
+
88
+ def test_returns_self_when_only_one_return_type_on_explode
89
+ expectation = Expectation.new(String, :new, :track, [])
90
+ expectation.add_return_values("rock")
91
+ assert_equal(expectation, expectation.explode)
92
+ end
77
93
  end
78
94
  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.10
4
+ version: 0.0.11
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-04-30 00:00:00 +01:00
12
+ date: 2008-05-14 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -78,7 +78,7 @@ post_install_message:
78
78
  rdoc_options:
79
79
  - --quiet
80
80
  - --title
81
- - Queueue
81
+ - Synthesis
82
82
  - --main
83
83
  - README
84
84
  - --inline-source