synthesis 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -51,5 +51,5 @@ Synthesis will currently ignore dynamically generated at runtime methods.
51
51
  == Related reading
52
52
 
53
53
  * Synthesized Testing: A Primer ( http://nutrun.com/weblog/synthesized-testing-a-primer )
54
- * Using Synthesis With Test::Unit and Mocha ( http://nutrun.com/weblog/using-synthesis-with-test-unit-and-mocha )
54
+ * Using Synthesis With Test::Unit and Mocha ( http://nutrun.com/weblog/using-synthesis-with-testunit-and-mocha )
55
55
  * Using Synthesis With Expectations ( http://nutrun.com/weblog/using-synthesis-with-expectations )
data/Rakefile CHANGED
@@ -71,7 +71,7 @@ end
71
71
 
72
72
  gem_spec = Gem::Specification.new do |s|
73
73
  s.name = 'synthesis'
74
- s.version = '0.0.1'
74
+ s.version = '0.0.2'
75
75
  s.platform = Gem::Platform::RUBY
76
76
  s.rubyforge_project = "synthesis"
77
77
  s.summary, s.description = 'A tool for Synthesized Testing'
data/lib/synthesis.rb CHANGED
@@ -5,6 +5,8 @@ $: << File.dirname(__FILE__)
5
5
  require "synthesis/logging"
6
6
  require "synthesis/recordable"
7
7
  require "synthesis/object"
8
+ require "synthesis/class"
9
+ require "synthesis/module"
8
10
  require "synthesis/expectation_record"
9
11
  require "synthesis/method_invocation_watcher"
10
12
  require "synthesis/expectation"
@@ -9,5 +9,6 @@ require "synthesis/adapter/mocha/object"
9
9
  require "synthesis/adapter/mocha/class_method"
10
10
  require "synthesis/adapter/mocha/expectation_record"
11
11
  require "synthesis/adapter/mocha/method_invocation_watcher"
12
+ require "synthesis/adapter/mocha/mocha_expectation"
12
13
  require "synthesis/adapter/expectations/expectations_adapter"
13
14
  require "synthesis/adapter/expectations/suite_runner"
@@ -9,4 +9,5 @@ require "synthesis/adapter/mocha/object"
9
9
  require "synthesis/adapter/mocha/class_method"
10
10
  require "synthesis/adapter/mocha/expectation_record"
11
11
  require "synthesis/adapter/mocha/method_invocation_watcher"
12
+ require "synthesis/adapter/mocha/mocha_expectation"
12
13
  require "synthesis/adapter/mocha/mocha_adapter"
@@ -0,0 +1,12 @@
1
+ module Mocha
2
+ class Expectation
3
+ attr_accessor :synthesis_expectation
4
+
5
+ alias mocha_with with
6
+
7
+ def with(*expected_parameters, &matching_block)
8
+ synthesis_expectation.args = expected_parameters if synthesis_expectation
9
+ mocha_with *expected_parameters, &matching_block
10
+ end
11
+ end
12
+ end
@@ -2,8 +2,10 @@ class Object
2
2
  alias mocha_expects expects
3
3
 
4
4
  def expects(meth)
5
- Synthesis::ExpectationRecord.add_expectation(self, meth)
6
- mocha_expects(meth)
5
+ s_expectation = Synthesis::ExpectationRecord.add_expectation(self, meth)
6
+ m_expectation = mocha_expects(meth)
7
+ m_expectation.synthesis_expectation = s_expectation
8
+ m_expectation
7
9
  end
8
10
 
9
11
  def mocked!
@@ -0,0 +1,5 @@
1
+ class Class
2
+ def expectation(method, args = [])
3
+ Synthesis::Expectation::Singleton.new(self, method, args)
4
+ end
5
+ end
@@ -1,16 +1,13 @@
1
1
  module Synthesis
2
2
  module Expectation
3
3
  def self.new(receiver, method, args = [])
4
- if receiver.is_a?(Class) || receiver.is_a?(Module)
5
- Singleton.new(receiver, method, args)
6
- else
7
- Instance.new(receiver, method, args)
8
- end
4
+ receiver.expectation method, args
9
5
  end
10
6
 
11
7
  class Expectation
12
8
  include Logging
13
- attr_reader :receiver, :method, :args
9
+ attr_reader :receiver, :method
10
+ attr_accessor :args
14
11
 
15
12
  def initialize(receiver, method, args)
16
13
  @receiver, @method, @args = receiver, method, args
@@ -34,6 +31,12 @@ module Synthesis
34
31
  def invoked!
35
32
  @invoked = true
36
33
  end
34
+
35
+ protected
36
+
37
+ def args_match?(other)
38
+ self.args.map { |arg| arg.class } == other.args.map { |arg| arg.class }
39
+ end
37
40
  end
38
41
 
39
42
  class Singleton < Expectation
@@ -42,7 +45,9 @@ module Synthesis
42
45
  end
43
46
 
44
47
  def eql?(other)
45
- @receiver.name == other.receiver.name && @method == other.method
48
+ @receiver.name == other.receiver.name &&
49
+ @method == other.method &&
50
+ args_match?(other)
46
51
  end
47
52
 
48
53
  def hash
@@ -50,7 +55,7 @@ module Synthesis
50
55
  end
51
56
 
52
57
  def to_s
53
- "#{@receiver.name}.#{@method}"
58
+ "#{@receiver.name}.#{@method}(#{@args.map { |arg| arg.class } * ', '})"
54
59
  end
55
60
  end
56
61
 
@@ -60,7 +65,9 @@ module Synthesis
60
65
  end
61
66
 
62
67
  def eql?(other)
63
- meta_receiver.name == other.meta_receiver.name && @method == other.method
68
+ meta_receiver.name == other.meta_receiver.name &&
69
+ @method == other.method &&
70
+ args_match?(other)
64
71
  end
65
72
 
66
73
  def hash
@@ -68,7 +75,7 @@ module Synthesis
68
75
  end
69
76
 
70
77
  def to_s
71
- "#{meta_receiver.name}.new.#{@method}"
78
+ "#{meta_receiver.name}.new.#{@method}(#{@args.map { |arg| arg.class } * ', '})"
72
79
  end
73
80
  end
74
81
 
@@ -4,7 +4,11 @@ module Synthesis
4
4
  include Logging
5
5
 
6
6
  def add_expectation(receiver, method, args = [])
7
- expectations << Expectation.new(receiver, method, args) unless ignore? receiver
7
+ unless ignore? receiver
8
+ expectation = Expectation.new(receiver, method, args)
9
+ expectations << expectation
10
+ expectation
11
+ end
8
12
  end
9
13
 
10
14
  def ignore(*args)
@@ -12,7 +16,9 @@ module Synthesis
12
16
  end
13
17
 
14
18
  def expectations
15
- @expectations ||= Set.new
19
+ @expectations ||= []
20
+ @expectations.uniq!
21
+ @expectations
16
22
  end
17
23
 
18
24
  def ignored
@@ -0,0 +1,5 @@
1
+ class Module
2
+ def expectation(method, args = [])
3
+ Synthesis::Expectation::Singleton.new(self, method, args)
4
+ end
5
+ end
@@ -2,4 +2,8 @@ class Object
2
2
  def __metaclass__
3
3
  class << self; self end
4
4
  end
5
+
6
+ def expectation(method, args = [])
7
+ Synthesis::Expectation::Instance.new(self, method, args)
8
+ end
5
9
  end
@@ -7,8 +7,7 @@ module Synthesis
7
7
  attr_accessor :verbose, :pattern, :ruby_opts, :adapter, :out
8
8
 
9
9
  def initialize(name='synthesis:test')
10
- @name = name
11
- @ignored = []
10
+ @name, @ignored = name, []
12
11
  yield self if block_given?
13
12
  @pattern ||= 'test/**/*.rb'
14
13
  @ruby_opts ||= []
@@ -0,0 +1,19 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "/../../../../lib/synthesis/adapter/mocha"
3
+
4
+ class MochaExpectationTest < Test::Unit::TestCase
5
+ def setup
6
+ @mocha_expectation = Mocha::Expectation.new :mock, :blah
7
+ end
8
+
9
+ def test_holds_synthesis_expectation
10
+ @mocha_expectation.synthesis_expectation = 1
11
+ assert_equal 1, @mocha_expectation.synthesis_expectation
12
+ end
13
+
14
+ def test_with_passes_expected_params_to_synthesis_expectation
15
+ @mocha_expectation.synthesis_expectation = Synthesis::Expectation.new(Hash, :foo)
16
+ @mocha_expectation.with 1, 2
17
+ assert_equal([1, 2], @mocha_expectation.synthesis_expectation.args)
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "/../../lib/synthesis"
3
+
4
+ class ClassTest < Test::Unit::TestCase
5
+ def test_has_singleton_expectation
6
+ assert_instance_of Synthesis::Expectation::Singleton, Hash.expectation(:foo)
7
+ end
8
+ end
@@ -42,5 +42,11 @@ module Synthesis
42
42
  ExpectationRecord.add_expectation Hash, :foo
43
43
  assert ExpectationRecord.expectations.empty?
44
44
  end
45
+
46
+ def test_returns_added_expectation_on_add
47
+ expected = Expectation.new Hash, :foo
48
+ actual = ExpectationRecord.add_expectation Hash, :foo
49
+ assert_equal expected, actual
50
+ end
45
51
  end
46
52
  end
@@ -43,6 +43,18 @@ module Synthesis
43
43
  exp2 = Expectation.new Array.new, :foo
44
44
  assert_not_equal exp1, exp2
45
45
  end
46
+
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]
50
+ assert_equal exp1, exp2
51
+ end
52
+
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]
56
+ assert_not_equal exp1, exp2
57
+ end
46
58
 
47
59
  def test_make_sure_equality_works_with_uniq
48
60
  arr = [
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "/../../lib/synthesis"
3
+
4
+ class ModuleTest < Test::Unit::TestCase
5
+ def test_has_singleton_expectation
6
+ assert_instance_of Synthesis::Expectation::Singleton, Module.new.expectation(:foo)
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "/../../lib/synthesis"
3
+
4
+ class ObjectTest < Test::Unit::TestCase
5
+ def test_has_instance_expectation
6
+ assert_instance_of Synthesis::Expectation::Instance, Object.new.expectation(:foo)
7
+ end
8
+ 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.1
4
+ version: 0.0.2
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-12 00:00:00 +00:00
12
+ date: 2008-01-14 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,13 +30,16 @@ files:
30
30
  - lib/synthesis/adapter/mocha/expectation_record.rb
31
31
  - lib/synthesis/adapter/mocha/method_invocation_watcher.rb
32
32
  - lib/synthesis/adapter/mocha/mocha_adapter.rb
33
+ - lib/synthesis/adapter/mocha/mocha_expectation.rb
33
34
  - lib/synthesis/adapter/mocha/object.rb
34
35
  - lib/synthesis/adapter/mocha.rb
35
36
  - lib/synthesis/adapter.rb
37
+ - lib/synthesis/class.rb
36
38
  - lib/synthesis/expectation.rb
37
39
  - lib/synthesis/expectation_record.rb
38
40
  - lib/synthesis/logging.rb
39
41
  - lib/synthesis/method_invocation_watcher.rb
42
+ - lib/synthesis/module.rb
40
43
  - lib/synthesis/object.rb
41
44
  - lib/synthesis/recordable.rb
42
45
  - lib/synthesis/report.rb
@@ -45,10 +48,14 @@ files:
45
48
  - lib/synthesis.rb
46
49
  - test/synthesis/adapter/mocha/expectation_record_test.rb
47
50
  - test/synthesis/adapter/mocha/method_invocation_watcher_test.rb
51
+ - test/synthesis/adapter/mocha/mocha_expectation_test.rb
48
52
  - test/synthesis/adapter/mocha/object_test.rb
53
+ - test/synthesis/class_test.rb
49
54
  - test/synthesis/expectation_record_test.rb
50
55
  - test/synthesis/expectation_test.rb
51
56
  - test/synthesis/method_invocation_watcher_test.rb
57
+ - test/synthesis/module_test.rb
58
+ - test/synthesis/object_test.rb
52
59
  - test/synthesis/recordable_test.rb
53
60
  - test_project/expectations/test/data_brander_test.rb
54
61
  - test_project/expectations/test/storage_test.rb