synthesis 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -67,6 +67,10 @@ To use with Expectations, redirecting output to a file
67
67
 
68
68
  Reporting the location (filename and line number) of tested/untested expectations doesn't work as intended with the Expectations adapter.
69
69
 
70
+ == Contributors
71
+
72
+ Danilo Sato, Paul Nasrat
73
+
70
74
  == Related reading
71
75
 
72
76
  * Synthesized Testing: A Primer ( http://nutrun.com/weblog/synthesized-testing-a-primer )
data/Rakefile CHANGED
@@ -91,7 +91,7 @@ end
91
91
 
92
92
  gem_spec = Gem::Specification.new do |s|
93
93
  s.name = 'synthesis'
94
- s.version = '0.0.9'
94
+ s.version = '0.0.10'
95
95
  s.platform = Gem::Platform::RUBY
96
96
  s.rubyforge_project = "synthesis"
97
97
  s.summary, s.description = 'A tool for Synthesized Testing'
@@ -2,7 +2,7 @@ module Synthesis
2
2
  class ExpectationRecord
3
3
  class << self
4
4
  include Logging
5
-
5
+
6
6
  def add_expectation(receiver, method, track, args = [])
7
7
  unless ignore? receiver
8
8
  expectation = Expectation.new(receiver, method, track, args)
@@ -10,56 +10,71 @@ module Synthesis
10
10
  expectation
11
11
  end
12
12
  end
13
-
13
+
14
14
  def ignore(*args)
15
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
20
+ # obj.expects(:method).with(:args)
21
+ # the +Expectation+ will be added when obj.expects(:method) is called
22
+ # the +Expectation+ arguments will be added when .with(:args) is called
19
23
  @expectations ||= []
20
24
  @expectations.uniq!
21
25
  @expectations
22
26
  end
23
-
27
+
24
28
  def ignored
25
29
  @ignored ||= Set.new
26
30
  end
27
-
31
+
28
32
  def [](matcher)
29
- expectations.detect { |e| e == matcher } || Expectation::NilExpectation.new
33
+ # Using a hash when recording invocations for improving performance
34
+ expectations_hash[matcher] || Expectation::NilExpectation.new
30
35
  end
31
-
36
+
32
37
  def record_invocations
33
38
  expectations.each { |e| e.record_invocations }
34
39
  end
35
-
40
+
36
41
  def tested_expectations
37
42
  expectations.select { |e| e.invoked? }
38
43
  end
39
-
44
+
40
45
  def untested_expectations
41
46
  expectations.select { |e| !e.invoked? }
42
- end
43
-
47
+ end
48
+
44
49
  def print_tested_expectations
45
50
  log; log "Tested Expectations: "
46
51
  tested_expectations.each { |e| log e }
47
52
  end
48
-
53
+
49
54
  def print_untested_expectations
50
55
  log; log "Untested Expectations: "
51
56
  untested_expectations.each { |e| log e }
52
57
  end
53
-
58
+
54
59
  def print_ignored
55
- log; log "Ignoring: #{ignored.to_a * ', '}"
60
+ log; log "Ignoring: #{ignored.to_a * ', '}"
56
61
  end
57
-
62
+
58
63
  private
59
-
64
+ def expectations_hash
65
+ @expectations_hash ||= expectations.inject({}) do |hash, expectation|
66
+ hash[expectation] = expectation
67
+ hash
68
+ end
69
+ end
70
+
60
71
  def ignore?(obj)
61
72
  ignored.include?(obj.class) || ignored.include?(obj) || obj.is_a?(MOCK_OBJECT)
62
- end
73
+ end
74
+
75
+ def reset!
76
+ @expectations_hash, @expectations, @ignored = nil
77
+ end
63
78
  end
64
79
  end
65
80
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/helper"
3
3
  module Synthesis
4
4
  class ExpectationRecordTest < Test::Unit::TestCase
5
5
  def teardown
6
- ExpectationRecord.expectations.clear
6
+ ExpectationRecord.send(:reset!)
7
7
  end
8
8
 
9
9
  def test_does_not_add_any_instance_expectation
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/helper"
3
3
  module Synthesis
4
4
  class ExpectationRecordTest < Test::Unit::TestCase
5
5
  def teardown
6
- ExpectationRecord.expectations.clear
6
+ ExpectationRecord.send(:reset!)
7
7
  end
8
8
 
9
9
  def test_does_not_add_any_instance_expectation
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/helper"
3
3
  module Synthesis
4
4
  class MethodsTest < Test::Unit::TestCase
5
5
  def teardown
6
- ExpectationRecord.expectations.clear
6
+ ExpectationRecord.send(:reset!)
7
7
  end
8
8
 
9
9
  def test_records_singleton_method_expectation
@@ -3,8 +3,7 @@ require File.dirname(__FILE__) + "/helper"
3
3
  module Synthesis
4
4
  class ExpectationRecordTest < Test::Unit::TestCase
5
5
  def teardown
6
- ExpectationRecord.expectations.clear
7
- ExpectationRecord.ignored.clear
6
+ ExpectationRecord.send(:reset!)
8
7
  end
9
8
 
10
9
  def test_adds_expectation
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + "/helper"
2
2
 
3
3
  module Synthesis
4
4
  class MethodInvocationWatcherTest < Test::Unit::TestCase
5
+ def teardown
6
+ ExpectationRecord.send(:reset!)
7
+ end
8
+
5
9
  def test_marks_expectation_invoked
6
10
  ExpectationRecord.add_expectation(Hash, :to_s, :track, []).add_return_values(1)
7
11
  MethodInvocationWatcher.invoked(Hash, :to_s, [], [1])
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.9
4
+ version: 0.0.10
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-21 00:00:00 +01:00
12
+ date: 2008-04-30 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15