synthesis 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -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.2'
61
+ s.version = '0.1.3'
62
62
  s.platform = Gem::Platform::RUBY
63
63
  s.rubyforge_project = "synthesis"
64
64
  s.summary, s.description = 'A tool for Synthesized Testing'
@@ -40,10 +40,6 @@ module Synthesis
40
40
  eql?(other)
41
41
  end
42
42
 
43
- def <=>(other)
44
- @return_values.size <=> other.return_values.size
45
- end
46
-
47
43
  def invoked?
48
44
  @invoked
49
45
  end
@@ -31,14 +31,23 @@ module Synthesis
31
31
  def [](matcher)
32
32
  # Using a hash for faster look up of expectations
33
33
  # when recording invocations
34
- expectations_hash[matcher] || Expectation::NilExpectation.new
34
+ expectations_with_return_values[matcher] ||
35
+ expectations_without_return_values[matcher] ||
36
+ Expectation::NilExpectation.new
35
37
  end
36
38
 
37
39
  def record_invocations
38
40
  expectations.map! { |e| e.explode }
39
41
  expectations.flatten!
40
42
  expectations.uniq!
41
- expectations.each { |e| e.record_invocations }
43
+ expectations.each do |e|
44
+ e.record_invocations
45
+ if e.return_values_defined?
46
+ expectations_with_return_values[e] = e
47
+ else
48
+ expectations_without_return_values[e] = e
49
+ end
50
+ end
42
51
  end
43
52
 
44
53
  def tested_expectations
@@ -64,11 +73,12 @@ module Synthesis
64
73
  end
65
74
 
66
75
  private
67
- def expectations_hash
68
- @expectations_hash ||= expectations.sort.inject({}) do |hash, expectation|
69
- hash[expectation] = expectation
70
- hash
71
- end
76
+ def expectations_with_return_values
77
+ @expectations_with_return_values ||= {}
78
+ end
79
+
80
+ def expectations_without_return_values
81
+ @expectations_without_return_values ||= {}
72
82
  end
73
83
 
74
84
  def ignore?(obj)
@@ -79,7 +89,9 @@ module Synthesis
79
89
  end
80
90
 
81
91
  def reset!
82
- @expectations_hash, @expectations, @ignored = nil
92
+ @expectations_with_return_values = nil
93
+ @expectations_without_return_values = nil
94
+ @expectations, @ignored = nil
83
95
  end
84
96
  end
85
97
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/helper"
3
3
  class MessageExpectationTest < Test::Unit::TestCase
4
4
  def setup
5
5
  error_generator = Class.new {def opts=(param)end}.new
6
- @spec_expectation = Spec::Mocks::MessageExpectation.new error_generator, :n, :n, :n, :n
6
+ @spec_expectation = Spec::Mocks::MessageExpectation.new(error_generator, :n, :n, :n, :n)
7
7
  end
8
8
 
9
9
  def test_holds_synthesis_expectation
@@ -12,7 +12,7 @@ class MessageExpectationTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_with_passes_expected_params_to_synthesis_expectation
15
- @spec_expectation.synthesis_expectation = Synthesis::Expectation.new Hash, :foo, :track
15
+ @spec_expectation.synthesis_expectation = Synthesis::Expectation.new(Hash, :foo, :track)
16
16
  @spec_expectation.with 1, 2
17
17
  assert_equal([1, 2], @spec_expectation.synthesis_expectation.args)
18
18
  end
@@ -7,7 +7,7 @@ module Synthesis
7
7
  end
8
8
 
9
9
  def test_adds_expectation
10
- ExpectationRecord.add_expectation Object.new, :to_s, :track
10
+ ExpectationRecord.add_expectation(Object.new, :to_s, :track)
11
11
  assert_equal(1, ExpectationRecord.expectations.size)
12
12
  end
13
13
 
@@ -21,16 +21,18 @@ module Synthesis
21
21
  end
22
22
 
23
23
  def test_finds_expectation
24
- expected = ExpectationRecord.add_expectation(Object.new, :foo, :track)
24
+ c = Class.new { def foo; end }
25
+ expected = ExpectationRecord.add_expectation(c.new, :foo, :track)
25
26
  expected.add_return_values(20)
26
- matcher = Expectation.new(Object.new, :foo, :track, [], [20])
27
+ ExpectationRecord.record_invocations
28
+ matcher = Expectation.new(c.new, :foo, :track, [], [20])
27
29
  actual = ExpectationRecord[matcher]
28
30
  assert_equal(expected, actual)
29
31
  end
30
32
 
31
33
  def test_returns_nil_expectation_on_no_expectation_found
32
- ExpectationRecord.add_expectation Object.new, :foo, :track
33
- matcher = Expectation.new Object.new, :bar, :track
34
+ ExpectationRecord.add_expectation(Object.new, :foo, :track)
35
+ matcher = Expectation.new(Object.new, :bar, :track)
34
36
  actual_instance = ExpectationRecord[matcher]
35
37
  assert_kind_of(Expectation::NilExpectation, actual_instance)
36
38
  end
@@ -61,15 +63,17 @@ module Synthesis
61
63
  end
62
64
 
63
65
  def test_uniqs_expectations_before_recording_invocations
64
- ExpectationRecord.add_expectation(Hash, :foo, :track)
65
- ExpectationRecord.add_expectation(Hash, :foo, :track)
66
+ c = Class.new { def foo; end }
67
+ ExpectationRecord.add_expectation(c, :foo, :track)
68
+ ExpectationRecord.add_expectation(c, :foo, :track)
66
69
  assert_equal(2, ExpectationRecord.expectations.size)
67
70
  ExpectationRecord.record_invocations
68
71
  assert_equal(1, ExpectationRecord.expectations.size)
69
72
  end
70
73
 
71
74
  def test_flattens_expectations_before_recording_invocations
72
- expectation = ExpectationRecord.add_expectation(Hash, :foo, :track)
75
+ c = Class.new { def foo; end }
76
+ expectation = ExpectationRecord.add_expectation(c, :foo, :track)
73
77
  expectation.add_return_values(1, "str", "sym")
74
78
  ExpectationRecord.record_invocations
75
79
  ExpectationRecord.expectations.each { |val| assert(!val.is_a?(Array)) }
@@ -108,13 +108,5 @@ module Synthesis
108
108
  expectation.add_return_values("rock")
109
109
  assert_equal(expectation, expectation.explode)
110
110
  end
111
-
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])
118
- end
119
111
  end
120
112
  end
@@ -7,8 +7,10 @@ module Synthesis
7
7
  end
8
8
 
9
9
  def test_marks_expectation_invoked
10
- ExpectationRecord.add_expectation(Hash, :to_s, :track, []).add_return_values(1)
11
- MethodInvocationWatcher.invoked(Hash, :to_s, [], [1])
10
+ c = Class.new { def foo; end }
11
+ ExpectationRecord.add_expectation(c, :to_s, :track, []).add_return_values(1)
12
+ ExpectationRecord.record_invocations
13
+ MethodInvocationWatcher.invoked(c, :to_s, [], [1])
12
14
  expectation = ExpectationRecord.expectations.to_a.first
13
15
  assert(expectation.invoked?)
14
16
  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.2
4
+ version: 0.1.3
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-06-04 00:00:00 +01:00
12
+ date: 2008-06-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15