synthesis 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -8,6 +8,10 @@ Currently we believe that developers are writing unnecessary functional tests to
8
8
 
9
9
  sudo gem i synthesis
10
10
 
11
+ == Download
12
+
13
+ Synthesis RubyForge page ( http://rubyforge.org/projects/synthesis )
14
+
11
15
  == Dependencies
12
16
 
13
17
  Synthesis's core doesn't have any dependencies.
@@ -52,4 +56,5 @@ Synthesis will currently ignore dynamically generated at runtime methods.
52
56
 
53
57
  * Synthesized Testing: A Primer ( http://nutrun.com/weblog/synthesized-testing-a-primer )
54
58
  * Using Synthesis With Test::Unit and Mocha ( http://nutrun.com/weblog/using-synthesis-with-testunit-and-mocha )
55
- * Using Synthesis With Expectations ( http://nutrun.com/weblog/using-synthesis-with-expectations )
59
+ * Using Synthesis With Expectations ( http://nutrun.com/weblog/using-synthesis-with-expectations )
60
+ * Synthesis validates simulated method calls taking method signature arguments into account ( http://nutrun.com/weblog/synthesis-002 )
data/Rakefile CHANGED
@@ -71,13 +71,13 @@ end
71
71
 
72
72
  gem_spec = Gem::Specification.new do |s|
73
73
  s.name = 'synthesis'
74
- s.version = '0.0.2'
74
+ s.version = '0.0.3'
75
75
  s.platform = Gem::Platform::RUBY
76
76
  s.rubyforge_project = "synthesis"
77
77
  s.summary, s.description = 'A tool for Synthesized Testing'
78
78
  s.author = 'Stuart Caborn, George Malamidis'
79
79
  s.email = 'george@nutrun.com'
80
- s.homepage = 'http://nutrun.com/synthesis'
80
+ s.homepage = 'http://synthesis.rubyforge.org'
81
81
  s.has_rdoc = true
82
82
  s.rdoc_options += ['--quiet', '--title', 'Queueue', '--main', 'README', '--inline-source']
83
83
  s.extra_rdoc_files = ['README', 'COPYING']
@@ -89,4 +89,7 @@ end
89
89
  Rake::GemPackageTask.new(gem_spec) do |t|
90
90
  t.need_zip = false
91
91
  t.need_tar = false
92
- end
92
+ end
93
+
94
+ desc "Remove rdoc and package artefacts"
95
+ task :clean => ['clobber_package', 'clobber_rdoc']
@@ -3,10 +3,10 @@ module Synthesis
3
3
  class << self
4
4
  alias_method :add_mocha_expectation, :add_expectation
5
5
 
6
- def add_expectation(obj, meth, args = [])
6
+ def add_expectation(obj, meth, track, args = [])
7
7
  # Ignone things like "foo = mock"
8
8
  return nil if obj.is_a?(Class::AnyInstance)
9
- add_mocha_expectation(obj, meth, args)
9
+ add_mocha_expectation(obj, meth, track, args)
10
10
  end
11
11
  end
12
12
  end
@@ -2,7 +2,7 @@ class Object
2
2
  alias mocha_expects expects
3
3
 
4
4
  def expects(meth)
5
- s_expectation = Synthesis::ExpectationRecord.add_expectation(self, meth)
5
+ s_expectation = Synthesis::ExpectationRecord.add_expectation(self, meth, caller[0])
6
6
  m_expectation = mocha_expects(meth)
7
7
  m_expectation.synthesis_expectation = s_expectation
8
8
  m_expectation
@@ -1,5 +1,5 @@
1
1
  class Class
2
- def expectation(method, args = [])
3
- Synthesis::Expectation::Singleton.new(self, method, args)
2
+ def expectation(method, track, args = [])
3
+ Synthesis::Expectation::Singleton.new(self, method, track, args)
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  module Synthesis
2
2
  module Expectation
3
- def self.new(receiver, method, args = [])
4
- receiver.expectation method, args
3
+ def self.new(receiver, method, track, args = [])
4
+ receiver.expectation method, track, args
5
5
  end
6
6
 
7
7
  class Expectation
@@ -9,8 +9,8 @@ module Synthesis
9
9
  attr_reader :receiver, :method
10
10
  attr_accessor :args
11
11
 
12
- def initialize(receiver, method, args)
13
- @receiver, @method, @args = receiver, method, args
12
+ def initialize(receiver, method, track, args)
13
+ @receiver, @method, @track, @args = receiver, method, track, args
14
14
  end
15
15
 
16
16
  def record_invocations
@@ -55,7 +55,7 @@ module Synthesis
55
55
  end
56
56
 
57
57
  def to_s
58
- "#{@receiver.name}.#{@method}(#{@args.map { |arg| arg.class } * ', '})"
58
+ "#{@receiver.name}.#{@method}(#{@args.map { |arg| arg.class } * ', '}) in #{@track}"
59
59
  end
60
60
  end
61
61
 
@@ -75,7 +75,7 @@ module Synthesis
75
75
  end
76
76
 
77
77
  def to_s
78
- "#{meta_receiver.name}.new.#{@method}(#{@args.map { |arg| arg.class } * ', '})"
78
+ "#{meta_receiver.name}.new.#{@method}(#{@args.map { |arg| arg.class } * ', '}) in #{@track}"
79
79
  end
80
80
  end
81
81
 
@@ -3,9 +3,9 @@ module Synthesis
3
3
  class << self
4
4
  include Logging
5
5
 
6
- def add_expectation(receiver, method, args = [])
6
+ def add_expectation(receiver, method, track, args = [])
7
7
  unless ignore? receiver
8
- expectation = Expectation.new(receiver, method, args)
8
+ expectation = Expectation.new(receiver, method, track, args)
9
9
  expectations << expectation
10
10
  expectation
11
11
  end
@@ -1,7 +1,7 @@
1
1
  module Synthesis
2
2
  class MethodInvocationWatcher
3
3
  def self.invoked(receiver, method, args = [])
4
- matcher = Expectation.new(receiver, method, args)
4
+ matcher = Expectation.new(receiver, method, nil, args)
5
5
  ExpectationRecord[matcher].invoked!
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  class Module
2
- def expectation(method, args = [])
3
- Synthesis::Expectation::Singleton.new(self, method, args)
2
+ def expectation(method, track, args = [])
3
+ Synthesis::Expectation::Singleton.new(self, method, track, args)
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ class Object
3
3
  class << self; self end
4
4
  end
5
5
 
6
- def expectation(method, args = [])
7
- Synthesis::Expectation::Instance.new(self, method, args)
6
+ def expectation(method, track, args = [])
7
+ Synthesis::Expectation::Instance.new(self, method, track, args)
8
8
  end
9
9
  end
@@ -1,8 +1,10 @@
1
1
  module Synthesis
2
2
  module Recordable
3
3
  def recordable_method(method)
4
- alias_method "__recordable__#{method}", method
5
- class_eval @@recordable_method_def[method]
4
+ unless method_defined? "__recordable__#{method}".intern
5
+ alias_method "__recordable__#{method}".intern, method
6
+ class_eval @@recordable_method_def[method]
7
+ end
6
8
  end
7
9
 
8
10
  @@recordable_method_def = proc { |method| %(
@@ -9,7 +9,7 @@ module Synthesis
9
9
 
10
10
  def test_does_not_add_any_instance_expectation
11
11
  any = Class::AnyInstance.new(Object)
12
- ExpectationRecord.add_expectation(any, :foo)
12
+ ExpectationRecord.add_expectation(any, :foo, :track)
13
13
  assert_equal(0, ExpectationRecord.expectations.size)
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module Synthesis
9
9
 
10
10
  def test_ignores_invocation_for_mocked_object
11
11
  foo = Class.new { def self.bar;end }
12
- ExpectationRecord.add_expectation foo, :bar
12
+ ExpectationRecord.add_expectation foo, :bar, :track
13
13
  ExpectationRecord.record_invocations
14
14
  e = ExpectationRecord.expectations.to_a[0]
15
15
  foo.expects(:bar)
@@ -19,7 +19,7 @@ module Synthesis
19
19
 
20
20
  def test_records_invocation_for_non_mocked_object
21
21
  foo = Class.new { def self.bar;end }
22
- ExpectationRecord.add_expectation foo, :bar
22
+ ExpectationRecord.add_expectation foo, :bar, :track
23
23
  ExpectationRecord.record_invocations
24
24
  e = ExpectationRecord.expectations.to_a[0]
25
25
  foo.bar
@@ -12,7 +12,7 @@ class MochaExpectationTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_with_passes_expected_params_to_synthesis_expectation
15
- @mocha_expectation.synthesis_expectation = Synthesis::Expectation.new(Hash, :foo)
15
+ @mocha_expectation.synthesis_expectation = Synthesis::Expectation.new Hash, :foo, :track
16
16
  @mocha_expectation.with 1, 2
17
17
  assert_equal([1, 2], @mocha_expectation.synthesis_expectation.args)
18
18
  end
@@ -4,14 +4,14 @@ require File.dirname(__FILE__) + "/../../../../lib/synthesis/adapter/mocha"
4
4
  module Synthesis
5
5
  class ObjectTest < Test::Unit::TestCase
6
6
  def test_records_singleton_method_expectation
7
- ExpectationRecord.expects(:add_expectation).with(Hash, :foo)
7
+ ExpectationRecord.expects(:add_expectation).with(Hash, :foo, kind_of(String))
8
8
  Hash.expects(:foo)
9
9
  Hash.foo
10
10
  end
11
11
 
12
12
  def test_records_instance_method_expectation
13
13
  hash = Hash.new
14
- ExpectationRecord.expects(:add_expectation).with(hash, :foo)
14
+ ExpectationRecord.expects(:add_expectation).with(hash, :foo, kind_of(String))
15
15
  hash.expects(:foo)
16
16
  hash.foo
17
17
  end
@@ -3,6 +3,6 @@ require File.dirname(__FILE__) + "/../../lib/synthesis"
3
3
 
4
4
  class ClassTest < Test::Unit::TestCase
5
5
  def test_has_singleton_expectation
6
- assert_instance_of Synthesis::Expectation::Singleton, Hash.expectation(:foo)
6
+ assert_instance_of Synthesis::Expectation::Singleton, Hash.expectation(:foo, :track)
7
7
  end
8
8
  end
@@ -9,13 +9,13 @@ module Synthesis
9
9
  end
10
10
 
11
11
  def test_adds_expectation
12
- ExpectationRecord.add_expectation Object.new, :to_s
12
+ ExpectationRecord.add_expectation Object.new, :to_s, :track
13
13
  assert_equal(1, ExpectationRecord.expectations.size)
14
14
  end
15
15
 
16
16
  def test_watches_expectation_invocations
17
17
  c = Class.new { def foo; end }
18
- ExpectationRecord.add_expectation c.new, :foo
18
+ ExpectationRecord.add_expectation c.new, :foo, :track
19
19
  ExpectationRecord.record_invocations
20
20
  a = c.new
21
21
  MethodInvocationWatcher.expects(:invoked).with(a, :foo, [])
@@ -23,29 +23,29 @@ module Synthesis
23
23
  end
24
24
 
25
25
  def test_finds_expectation
26
- ExpectationRecord.add_expectation Object.new, :foo
26
+ ExpectationRecord.add_expectation Object.new, :foo, :track
27
27
  expected = ExpectationRecord.expectations.to_a[0]
28
- matcher = Expectation.new Object.new, :foo
28
+ matcher = Expectation.new Object.new, :foo, :track
29
29
  actual = ExpectationRecord[matcher]
30
30
  assert_equal(expected, actual)
31
31
  end
32
32
 
33
33
  def test_returns_nil_expectation_on_no_expectation_found
34
- ExpectationRecord.add_expectation Object.new, :foo
35
- matcher = Expectation.new Object.new, :bar
34
+ ExpectationRecord.add_expectation Object.new, :foo, :track
35
+ matcher = Expectation.new Object.new, :bar, :track
36
36
  actual_instance = ExpectationRecord[matcher]
37
37
  assert_kind_of Expectation::NilExpectation, actual_instance
38
38
  end
39
39
 
40
40
  def test_does_not_add_expectation_for_ignored_class
41
41
  ExpectationRecord.ignore Hash
42
- ExpectationRecord.add_expectation Hash, :foo
42
+ ExpectationRecord.add_expectation Hash, :foo, :track
43
43
  assert ExpectationRecord.expectations.empty?
44
44
  end
45
45
 
46
46
  def test_returns_added_expectation_on_add
47
- expected = Expectation.new Hash, :foo
48
- actual = ExpectationRecord.add_expectation Hash, :foo
47
+ expected = Expectation.new Hash, :foo, :track
48
+ actual = ExpectationRecord.add_expectation Hash, :foo, :track
49
49
  assert_equal expected, actual
50
50
  end
51
51
  end
@@ -4,55 +4,55 @@ require File.dirname(__FILE__) + "/../../lib/synthesis"
4
4
  module Synthesis
5
5
  class ExpectationTest < Test::Unit::TestCase
6
6
  def test_creates_singleton_method_expectation_given_class
7
- expectation = Expectation.new Class.new, :foo
7
+ expectation = Expectation.new Class.new, :foo, :track
8
8
  assert_kind_of Expectation::Singleton, expectation
9
9
  end
10
10
 
11
11
  def test_creates_instance_method_expectation_given_instance
12
- expectation = Expectation.new Class.new.new, :foo
12
+ expectation = Expectation.new Class.new.new, :foo, :track
13
13
  assert_kind_of Expectation::Instance, expectation
14
14
  end
15
15
 
16
16
  def test_creates_singleton_method_expectation_given_module
17
- expectation = Expectation.new Module.new, :foo
17
+ expectation = Expectation.new Module.new, :foo, :track
18
18
  assert_kind_of Expectation::Singleton, expectation
19
19
  end
20
20
 
21
21
  def test_records_instance_receiver_method_invocations
22
22
  receiver = Class.new { def foo;end }
23
- expectation = Expectation.new receiver.new, :foo
23
+ expectation = Expectation.new receiver.new, :foo, :track
24
24
  expectation.record_invocations
25
25
  assert_respond_to receiver.new, :__recordable__foo
26
26
  end
27
27
 
28
28
  def test_records_singleton_receiver_method_invocations
29
29
  receiver = Class.new { def self.foo;end }
30
- expectation = Expectation.new receiver, :foo
30
+ expectation = Expectation.new receiver, :foo, :track
31
31
  expectation.record_invocations
32
32
  assert_respond_to receiver, :__recordable__foo
33
33
  end
34
34
 
35
35
  def test_equality
36
- exp1 = Expectation.new Object.new, :foo
37
- exp2 = Expectation.new Object.new, :foo
36
+ exp1 = Expectation.new Object.new, :foo, :track
37
+ exp2 = Expectation.new Object.new, :foo, :track
38
38
  assert_equal exp1, exp2
39
39
  end
40
40
 
41
41
  def test_non_equality
42
- exp1 = Expectation.new Hash.new, :foo
43
- exp2 = Expectation.new Array.new, :foo
42
+ exp1 = Expectation.new Hash.new, :foo, :track
43
+ exp2 = Expectation.new Array.new, :foo, :track
44
44
  assert_not_equal exp1, exp2
45
45
  end
46
46
 
47
47
  def test_equality_based_on_same_type_args
48
- exp1 = Expectation.new Object.new, :foo, [1, 2]
49
- exp2 = Expectation.new Object.new, :foo, [1, 2]
48
+ exp1 = Expectation.new Object.new, :foo, :track, [1, 2]
49
+ exp2 = Expectation.new Object.new, :foo, :track, [1, 2]
50
50
  assert_equal exp1, exp2
51
51
  end
52
52
 
53
53
  def test_args_based_non_equality_based_on_different_type_args
54
- exp1 = Expectation.new Object.new, :foo, [1, Hash.new]
55
- exp2 = Expectation.new Object.new, :foo, [1, 2]
54
+ exp1 = Expectation.new Object.new, :foo, :track, [1, Hash.new]
55
+ exp2 = Expectation.new Object.new, :foo, :track, [1, 2]
56
56
  assert_not_equal exp1, exp2
57
57
  end
58
58
 
@@ -65,7 +65,7 @@ module Synthesis
65
65
  end
66
66
 
67
67
  def test_does_not_blow_up_on_name_error
68
- expectation = Expectation.new(Hash, :bad)
68
+ expectation = Expectation.new Hash, :bad, :track
69
69
  silent(expectation) do
70
70
  assert_nothing_raised(NameError) { expectation.record_invocations }
71
71
  end
@@ -3,6 +3,6 @@ require File.dirname(__FILE__) + "/../../lib/synthesis"
3
3
 
4
4
  class ModuleTest < Test::Unit::TestCase
5
5
  def test_has_singleton_expectation
6
- assert_instance_of Synthesis::Expectation::Singleton, Module.new.expectation(:foo)
6
+ assert_instance_of Synthesis::Expectation::Singleton, Module.new.expectation(:foo, :track)
7
7
  end
8
8
  end
@@ -3,6 +3,6 @@ require File.dirname(__FILE__) + "/../../lib/synthesis"
3
3
 
4
4
  class ObjectTest < Test::Unit::TestCase
5
5
  def test_has_instance_expectation
6
- assert_instance_of Synthesis::Expectation::Instance, Object.new.expectation(:foo)
6
+ assert_instance_of Synthesis::Expectation::Instance, Object.new.expectation(:foo, :track)
7
7
  end
8
8
  end
@@ -17,6 +17,14 @@ module Synthesis
17
17
  bar = foo.new
18
18
  MethodInvocationWatcher.expects(:invoked).with(bar, :b, [])
19
19
  bar.b
20
- end
20
+ end
21
+
22
+ def test_does_not_redefine_already_redefined_method
23
+ foo = Class.new { def b; end }
24
+ foo.extend Recordable
25
+ foo.stubs(:method_defined?).returns(true)
26
+ foo.expects(:alias_method).never
27
+ foo.recordable_method(:b)
28
+ end
21
29
  end
22
30
  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.2
4
+ version: 0.0.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-01-14 00:00:00 +00:00
12
+ date: 2008-02-03 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -68,7 +68,7 @@ files:
68
68
  - README
69
69
  - Rakefile
70
70
  has_rdoc: true
71
- homepage: http://nutrun.com/synthesis
71
+ homepage: http://synthesis.rubyforge.org
72
72
  post_install_message:
73
73
  rdoc_options:
74
74
  - --quiet