synthesis 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/README +16 -5
  2. data/Rakefile +25 -5
  3. data/lib/synthesis/adapter/expectations.rb +16 -7
  4. data/lib/synthesis/adapter/mocha.rb +14 -8
  5. data/lib/synthesis/adapter/rspec.rb +19 -0
  6. data/lib/synthesis/adapter.rb +51 -7
  7. data/lib/synthesis/expectation_record.rb +1 -1
  8. data/test/synthesis/adapter/mocha/expectation_record_test.rb +1 -2
  9. data/test/synthesis/adapter/mocha/helper.rb +2 -0
  10. data/test/synthesis/adapter/mocha/mocha_expectation_test.rb +1 -2
  11. data/test/synthesis/adapter/mocha/mocha_test.rb +9 -0
  12. data/test/synthesis/adapter/mocha/object_test.rb +1 -2
  13. data/test/synthesis/adapter/rspec/expectation_record_test.rb +15 -0
  14. data/test/synthesis/adapter/rspec/helper.rb +2 -0
  15. data/test/synthesis/adapter/rspec/message_expectation_test.rb +19 -0
  16. data/test/synthesis/adapter/rspec/methods_test.rb +18 -0
  17. data/test/synthesis/class_test.rb +1 -2
  18. data/test/synthesis/expectation_record_test.rb +1 -2
  19. data/test/synthesis/expectation_test.rb +1 -2
  20. data/test/synthesis/helper.rb +3 -0
  21. data/test/synthesis/method_invocation_watcher_test.rb +1 -2
  22. data/test/synthesis/module_test.rb +1 -2
  23. data/test/synthesis/object_test.rb +1 -2
  24. data/test/synthesis/recordable_test.rb +1 -2
  25. data/test_project/expectations/test/data_brander_test.rb +1 -1
  26. data/test_project/mocha/test/data_brander_test.rb +6 -0
  27. data/test_project/rspec/data_brander_spec.rb +16 -0
  28. data/test_project/rspec/storage_spec.rb +13 -0
  29. metadata +12 -11
  30. data/lib/synthesis/adapter/expectations/expectations_adapter.rb +0 -7
  31. data/lib/synthesis/adapter/expectations/suite_runner.rb +0 -7
  32. data/lib/synthesis/adapter/mocha/class_method.rb +0 -17
  33. data/lib/synthesis/adapter/mocha/expectation_record.rb +0 -12
  34. data/lib/synthesis/adapter/mocha/method_invocation_watcher.rb +0 -11
  35. data/lib/synthesis/adapter/mocha/mocha_adapter.rb +0 -8
  36. data/lib/synthesis/adapter/mocha/mocha_expectation.rb +0 -12
  37. data/lib/synthesis/adapter/mocha/object.rb +0 -22
  38. data/test/synthesis/adapter/mocha/method_invocation_watcher_test.rb +0 -29
data/README CHANGED
@@ -16,13 +16,15 @@ Synthesis RubyForge page ( http://rubyforge.org/projects/synthesis )
16
16
 
17
17
  Synthesis's core doesn't have any dependencies.
18
18
 
19
- When used with the Expectations adapter, it will depend on the Expectations[http://expectations.rubyforge.org] library.
20
-
21
19
  When used with the Mocha adapter, it will depend on the Mocha[http://mocha.rubyforge.org] library.
22
20
 
21
+ When used with the RSpec adapter, it will depend on the RSpec[http://rspec.info/] library.
22
+
23
+ When used with the Expectations adapter, it will depend on the Expectations[http://expectations.rubyforge.org] library.
24
+
23
25
  == Usage
24
26
 
25
- Synthesis can be used through its Rake task. It currently has two supported adapters: Mocha (with Test::Unit) and Expectations. If +adapter+ is not explicitly specified, the Mocha adapter will be used by default.
27
+ Synthesis can be used through its Rake task. It currently has three supported adapters: Mocha (with Test::Unit), RSpec and Expectations. If +adapter+ is not explicitly specified, the Mocha adapter will be used by default.
26
28
 
27
29
  By default, Synthesis outputs to +STDOUT+, but output can be redirected to alternative IO streams.
28
30
 
@@ -30,6 +32,8 @@ Synthesis can be setup to ignore certain classes or modules when collecting expe
30
32
 
31
33
  If +pattern+ is not specified, it will default to <tt>test/**/*.rb</tt>
32
34
 
35
+ == Usage examples
36
+
33
37
  To use with Test::Unit and Mocha, ignoring Array and Hash:
34
38
 
35
39
  require "synthesis/task"
@@ -39,6 +43,15 @@ To use with Test::Unit and Mocha, ignoring Array and Hash:
39
43
  t.ignore Array, Hash
40
44
  end
41
45
 
46
+ To use with RSpec, running all specs in the <tt>specs</tt> directory:
47
+
48
+ require "synthesis/task"
49
+
50
+ Synthesis::Task.new do |t|
51
+ t.adapter = :rspec
52
+ t.pattern = 'specs/*_spec.rb'
53
+ end
54
+
42
55
  To use with Expectations, redirecting output to a file
43
56
 
44
57
  require "synthesis/task"
@@ -50,8 +63,6 @@ To use with Expectations, redirecting output to a file
50
63
 
51
64
  == Known Issues
52
65
 
53
- Synthesis will currently ignore dynamically generated at runtime methods.
54
-
55
66
  Reporting the location (filename and line number) of tested/untested expectations doesn't work as intended with the Expectations adapter.
56
67
 
57
68
  == Related reading
data/Rakefile CHANGED
@@ -6,8 +6,23 @@ require 'rake/contrib/sshpublisher'
6
6
  require File.dirname(__FILE__) + "/lib/synthesis/task"
7
7
 
8
8
  task :default => :test
9
- Rake::TestTask.new(:test) do |t|
10
- t.pattern = 'test/**/*_test.rb'
9
+
10
+ desc "Run all tests"
11
+ task :test => %w[test:core test:mocha test:spec]
12
+
13
+ desc "Run core tests"
14
+ Rake::TestTask.new('test:core') do |t|
15
+ t.pattern = 'test/synthesis/*_test.rb'
16
+ end
17
+
18
+ desc "Run Mocha adapter tests"
19
+ Rake::TestTask.new('test:mocha') do |t|
20
+ t.pattern = 'test/synthesis/adapter/mocha/*_test.rb'
21
+ end
22
+
23
+ desc "Run RSpec adapter tests"
24
+ Rake::TestTask.new('test:spec') do |t|
25
+ t.pattern = 'test/synthesis/adapter/rspec/*_test.rb'
11
26
  end
12
27
 
13
28
  Synthesis::Task.new('synthesis:test:expectations') do |t|
@@ -15,6 +30,11 @@ Synthesis::Task.new('synthesis:test:expectations') do |t|
15
30
  t.pattern = 'test_project/expectations/test/*_test.rb'
16
31
  end
17
32
 
33
+ Synthesis::Task.new('synthesis:test:rspec') do |t|
34
+ t.adapter = :rspec
35
+ t.pattern = 'test_project/rspec/*_spec.rb'
36
+ end
37
+
18
38
  Synthesis::Task.new do |t|
19
39
  t.pattern = 'test_project/mocha/test/*_test.rb'
20
40
  t.ignore Array, Hash
@@ -66,12 +86,12 @@ namespace :svn do
66
86
  end
67
87
 
68
88
  desc "Run before checking in"
69
- task :pc => ['svn:add', 'svn:delete', 'svn:up', :default, 'svn:st']
89
+ task :pc => %w[svn:add svn:delete svn:up default svn:st]
70
90
  end
71
91
 
72
92
  gem_spec = Gem::Specification.new do |s|
73
93
  s.name = 'synthesis'
74
- s.version = '0.0.5'
94
+ s.version = '0.0.6'
75
95
  s.platform = Gem::Platform::RUBY
76
96
  s.rubyforge_project = "synthesis"
77
97
  s.summary, s.description = 'A tool for Synthesized Testing'
@@ -92,4 +112,4 @@ Rake::GemPackageTask.new(gem_spec) do |t|
92
112
  end
93
113
 
94
114
  desc "Remove rdoc and package artefacts"
95
- task :clean => ['clobber_package', 'clobber_rdoc']
115
+ task :clean => %w[clobber_package clobber_rdoc]
@@ -5,10 +5,19 @@ require "expectations"
5
5
  $: << File.dirname(__FILE__) + "/../../"
6
6
 
7
7
  require "synthesis"
8
- require "synthesis/adapter/mocha/object"
9
- require "synthesis/adapter/mocha/class_method"
10
- require "synthesis/adapter/mocha/expectation_record"
11
- require "synthesis/adapter/mocha/method_invocation_watcher"
12
- require "synthesis/adapter/mocha/mocha_expectation"
13
- require "synthesis/adapter/expectations/expectations_adapter"
14
- require "synthesis/adapter/expectations/suite_runner"
8
+ require "synthesis/adapter/mocha"
9
+
10
+ module Synthesis
11
+ class ExpectationsAdapter < Adapter
12
+ def run
13
+ fail_unless { Expectations::SuiteRunner.instance.suite.execute }
14
+ end
15
+ end
16
+ end
17
+
18
+ class Expectations::SuiteRunner
19
+ def initialize
20
+ self.suite = Expectations::Suite.new
21
+ end
22
+ end
23
+
@@ -2,12 +2,18 @@ require "rubygems"
2
2
  require "mocha_standalone"
3
3
  require "test/unit"
4
4
 
5
- $: << File.dirname(__FILE__) + "/../../"
5
+ require File.dirname(__FILE__) + "/../../synthesis"
6
6
 
7
- require "synthesis"
8
- require "synthesis/adapter/mocha/object"
9
- require "synthesis/adapter/mocha/class_method"
10
- require "synthesis/adapter/mocha/expectation_record"
11
- require "synthesis/adapter/mocha/method_invocation_watcher"
12
- require "synthesis/adapter/mocha/mocha_expectation"
13
- require "synthesis/adapter/mocha/mocha_adapter"
7
+ module Synthesis
8
+ class MochaAdapter < Adapter
9
+
10
+ mock_object_type Class::AnyInstance
11
+ expectation_class Mocha::Expectation
12
+ intercept :method => :expects, :on => Object
13
+
14
+ def run
15
+ Test::Unit.run = true # Yes means no...
16
+ fail_unless { Test::Unit::AutoRunner.run }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require "spec/mocks"
4
+
5
+ require File.dirname(__FILE__) + "/../../synthesis"
6
+
7
+ module Synthesis
8
+ class RSpecAdapter < Adapter
9
+
10
+ mock_object_type Spec::Mocks::Mock
11
+ expectation_class Spec::Mocks::MessageExpectation
12
+ intercept :method => :should_receive, :on => Spec::Mocks::Methods
13
+
14
+ def run
15
+ rspec_options.files.clear
16
+ fail_unless { rspec_options.run_examples }
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,7 @@
1
1
  module Synthesis
2
- # Subclasses of Synthesis::Adapter must implement the run method
2
+ # Subclasses of Adapter must implement the "run" method.
3
+ # For example implementations, refer to Synthesis::MochaAdapter and
4
+ # Synthesis::RSpecAdapter
3
5
  class Adapter
4
6
  include Logging
5
7
 
@@ -7,6 +9,8 @@ module Synthesis
7
9
  @pattern = pattern
8
10
  end
9
11
 
12
+ # The block parameter will yield twice, once for collecting and
13
+ # once for verifying the collected expectations.
10
14
  def fail_unless(&block)
11
15
  log "Collecting expectations..."
12
16
  Dir[@pattern].each { |t| require t }
@@ -16,12 +20,52 @@ module Synthesis
16
20
  yield
17
21
  end
18
22
 
19
- def self.inherited(subclass)
20
- @adapter = subclass
21
- end
22
-
23
- def self.load(pattern)
24
- @adapter.new(pattern)
23
+ class << self
24
+ # The type of object representing a mock or stub for the test framework.
25
+ # Objects of this type will be ignored by Synthesis.
26
+ def mock_object_type(type)
27
+ Synthesis.const_set(:MOCK_OBJECT, type)
28
+ end
29
+
30
+ # The class representing a mock object expectation in the test framework.
31
+ # Synthesis will intercept its "with" method in order to collect the
32
+ # expectation method parameters being passed to it.
33
+ def expectation_class(klass)
34
+ klass.class_eval do
35
+ attr_accessor :synthesis_expectation
36
+
37
+ alias original_with with
38
+
39
+ def with(*expected_parameters, &matching_block)
40
+ synthesis_expectation.args = expected_parameters if synthesis_expectation
41
+ original_with *expected_parameters, &matching_block
42
+ end
43
+ end
44
+ end
45
+
46
+ # Accepts a Hash parameter with two entries, :method and :on. These
47
+ # represent the name of the method used for declaring a method interaction
48
+ # expectation on an object and the name of the object the method is defined
49
+ # on respectively. Synthesis will intercept this method in order to collect
50
+ # simulated method interactions.
51
+ def intercept(params)
52
+ method_name, obj = params[:method], params[:on]
53
+ obj.send(:alias_method, :original_meth, method_name)
54
+ obj.send(:define_method, method_name) do |meth|
55
+ s_expectation = Synthesis::ExpectationRecord.add_expectation(self, meth, caller[0])
56
+ m_expectation = original_meth(meth)
57
+ m_expectation.synthesis_expectation = s_expectation
58
+ m_expectation
59
+ end
60
+ end
61
+
62
+ def inherited(subclass)
63
+ @adapter = subclass
64
+ end
65
+
66
+ def load(pattern)
67
+ @adapter.new(pattern)
68
+ end
25
69
  end
26
70
  end
27
71
  end
@@ -58,7 +58,7 @@ module Synthesis
58
58
  private
59
59
 
60
60
  def ignore?(obj)
61
- ignored.include?(obj.class) || ignored.include?(obj)
61
+ ignored.include?(obj.class) || ignored.include?(obj) || obj.is_a?(MOCK_OBJECT)
62
62
  end
63
63
  end
64
64
  end
@@ -1,5 +1,4 @@
1
- require "test/unit"
2
- require File.dirname(__FILE__) + "/../../../../lib/synthesis/adapter/mocha"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  module Synthesis
5
4
  class ExpectationRecordTest < Test::Unit::TestCase
@@ -0,0 +1,2 @@
1
+ %w(test/unit rubygems mocha).each { |l| require l }
2
+ require File.dirname(__FILE__) + "/../../../../lib/synthesis/adapter/mocha"
@@ -1,5 +1,4 @@
1
- require "test/unit"
2
- require File.dirname(__FILE__) + "/../../../../lib/synthesis/adapter/mocha"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  class MochaExpectationTest < Test::Unit::TestCase
5
4
  def setup
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ module Synthesis
4
+ class MochaTest < Test::Unit::TestCase
5
+ def test_sets_mock_object_to_class_any_instance
6
+ assert_equal(Class::AnyInstance, Synthesis::MOCK_OBJECT)
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,4 @@
1
- %w(test/unit rubygems mocha).each { |l| require l }
2
- require File.dirname(__FILE__) + "/../../../../lib/synthesis/adapter/mocha"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  module Synthesis
5
4
  class ObjectTest < Test::Unit::TestCase
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ module Synthesis
4
+ class ExpectationRecordTest < Test::Unit::TestCase
5
+ def teardown
6
+ ExpectationRecord.expectations.clear
7
+ end
8
+
9
+ def test_does_not_add_any_instance_expectation
10
+ mock = Spec::Mocks::Mock.new(Numeric)
11
+ ExpectationRecord.add_expectation(mock, :foo, :track)
12
+ assert_equal(0, ExpectationRecord.expectations.size)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "/../../../../lib/synthesis/adapter/rspec"
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class MessageExpectationTest < Test::Unit::TestCase
4
+ def setup
5
+ error_generator = Class.new {def opts=(param)end}.new
6
+ @spec_expectation = Spec::Mocks::MessageExpectation.new error_generator, :n, :n, :n, :n
7
+ end
8
+
9
+ def test_holds_synthesis_expectation
10
+ @spec_expectation.synthesis_expectation = 1
11
+ assert_equal 1, @spec_expectation.synthesis_expectation
12
+ end
13
+
14
+ def test_with_passes_expected_params_to_synthesis_expectation
15
+ @spec_expectation.synthesis_expectation = Synthesis::Expectation.new Hash, :foo, :track
16
+ @spec_expectation.with 1, 2
17
+ assert_equal([1, 2], @spec_expectation.synthesis_expectation.args)
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ module Synthesis
4
+ class MethodsTest < Test::Unit::TestCase
5
+ def test_records_singleton_method_expectation
6
+ ExpectationRecord.should_receive(:add_expectation).with(Hash, :foo, an_instance_of(String))
7
+ Hash.should_receive(:foo)
8
+ Hash.foo
9
+ end
10
+
11
+ def test_records_instance_method_expectation
12
+ hash = Hash.new
13
+ ExpectationRecord.should_receive(:add_expectation).with(hash, :foo, an_instance_of(String))
14
+ hash.should_receive(:foo)
15
+ hash.foo
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,4 @@
1
- require "test/unit"
2
- require File.dirname(__FILE__) + "/../../lib/synthesis"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  class ClassTest < Test::Unit::TestCase
5
4
  def test_has_singleton_expectation
@@ -1,5 +1,4 @@
1
- %w(test/unit rubygems mocha).each { |l| require l }
2
- require File.dirname(__FILE__) + "/../../lib/synthesis"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  module Synthesis
5
4
  class ExpectationRecordTest < Test::Unit::TestCase
@@ -1,5 +1,4 @@
1
- require "test/unit"
2
- require File.dirname(__FILE__) + "/../../lib/synthesis"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  module Synthesis
5
4
  class ExpectationTest < Test::Unit::TestCase
@@ -0,0 +1,3 @@
1
+ %w(test/unit rubygems mocha).each { |l| require l }
2
+ require File.dirname(__FILE__) + "/../../lib/synthesis"
3
+ MOCK_OBJECT = Class.new {} # FIXME: should find a better way of doing this...
@@ -1,5 +1,4 @@
1
- %w(test/unit rubygems mocha).each { |l| require l }
2
- require File.dirname(__FILE__) + "/../../lib/synthesis"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  module Synthesis
5
4
  class MethodInvocationWatcherTest < Test::Unit::TestCase
@@ -1,5 +1,4 @@
1
- require "test/unit"
2
- require File.dirname(__FILE__) + "/../../lib/synthesis"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  class ModuleTest < Test::Unit::TestCase
5
4
  def test_has_singleton_expectation
@@ -1,5 +1,4 @@
1
- require "test/unit"
2
- require File.dirname(__FILE__) + "/../../lib/synthesis"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  class ObjectTest < Test::Unit::TestCase
5
4
  def test_has_instance_expectation
@@ -1,5 +1,4 @@
1
- %w(test/unit rubygems mocha).each { |l| require l }
2
- require File.dirname(__FILE__) + "/../../lib/synthesis"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  module Synthesis
5
4
  class RecordableTest < Test::Unit::TestCase
@@ -3,7 +3,7 @@ require "expectations"
3
3
  require File.dirname(__FILE__) + "/../../test_project"
4
4
 
5
5
  Expectations do
6
- expect Storage.new('whatever').to_receive(:save).with('METAL - rock') do |storage|
6
+ expect Storage.new('whatever').to.receive(:save).with('METAL - rock') do |storage|
7
7
  DataBrander.new(storage).save_branded 'rock'
8
8
  end
9
9
  end
@@ -7,4 +7,10 @@ class DataBranderTest < Test::Unit::TestCase
7
7
  pstore.expects(:save).with('METAL - rock')
8
8
  DataBrander.new(pstore).save_branded 'rock'
9
9
  end
10
+
11
+ def test_ignores_total_ducks
12
+ m = mock
13
+ m.expects(:foo)
14
+ m.foo
15
+ end
10
16
  end
@@ -0,0 +1,16 @@
1
+ %w(rubygems spec fileutils).each { |l| require l }
2
+ require File.dirname(__FILE__) + "/../test_project"
3
+
4
+ describe DataBrander do
5
+ it "should save branded to pstore" do
6
+ pstore = Storage.new 'whatever'
7
+ pstore.should_receive(:save).with('METAL - rock')
8
+ DataBrander.new(pstore).save_branded 'rock'
9
+ end
10
+
11
+ it "should ignore total ducks" do
12
+ m = mock(Storage)
13
+ m.should_receive(:foo)
14
+ m.foo
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ %w(rubygems spec fileutils).each { |l| require l }
2
+ require File.dirname(__FILE__) + "/../test_project"
3
+
4
+ describe Storage do
5
+ it "should save to file" do
6
+ begin
7
+ Storage.new('test.txt').save('rock')
8
+ File.read('test.txt').should == 'rock'
9
+ ensure
10
+ FileUtils.rm_f('test.txt')
11
+ end
12
+ end
13
+ 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.5
4
+ version: 0.0.6
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-02-05 00:00:00 +00:00
12
+ date: 2008-03-09 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,16 +23,9 @@ extra_rdoc_files:
23
23
  - README
24
24
  - COPYING
25
25
  files:
26
- - lib/synthesis/adapter/expectations/expectations_adapter.rb
27
- - lib/synthesis/adapter/expectations/suite_runner.rb
28
26
  - lib/synthesis/adapter/expectations.rb
29
- - lib/synthesis/adapter/mocha/class_method.rb
30
- - lib/synthesis/adapter/mocha/expectation_record.rb
31
- - lib/synthesis/adapter/mocha/method_invocation_watcher.rb
32
- - lib/synthesis/adapter/mocha/mocha_adapter.rb
33
- - lib/synthesis/adapter/mocha/mocha_expectation.rb
34
- - lib/synthesis/adapter/mocha/object.rb
35
27
  - lib/synthesis/adapter/mocha.rb
28
+ - lib/synthesis/adapter/rspec.rb
36
29
  - lib/synthesis/adapter.rb
37
30
  - lib/synthesis/class.rb
38
31
  - lib/synthesis/expectation.rb
@@ -47,12 +40,18 @@ files:
47
40
  - lib/synthesis/task.rb
48
41
  - lib/synthesis.rb
49
42
  - test/synthesis/adapter/mocha/expectation_record_test.rb
50
- - test/synthesis/adapter/mocha/method_invocation_watcher_test.rb
43
+ - test/synthesis/adapter/mocha/helper.rb
51
44
  - test/synthesis/adapter/mocha/mocha_expectation_test.rb
45
+ - test/synthesis/adapter/mocha/mocha_test.rb
52
46
  - test/synthesis/adapter/mocha/object_test.rb
47
+ - test/synthesis/adapter/rspec/expectation_record_test.rb
48
+ - test/synthesis/adapter/rspec/helper.rb
49
+ - test/synthesis/adapter/rspec/message_expectation_test.rb
50
+ - test/synthesis/adapter/rspec/methods_test.rb
53
51
  - test/synthesis/class_test.rb
54
52
  - test/synthesis/expectation_record_test.rb
55
53
  - test/synthesis/expectation_test.rb
54
+ - test/synthesis/helper.rb
56
55
  - test/synthesis/method_invocation_watcher_test.rb
57
56
  - test/synthesis/module_test.rb
58
57
  - test/synthesis/object_test.rb
@@ -63,6 +62,8 @@ files:
63
62
  - test_project/lib/storage.rb
64
63
  - test_project/mocha/test/data_brander_test.rb
65
64
  - test_project/mocha/test/storage_test.rb
65
+ - test_project/rspec/data_brander_spec.rb
66
+ - test_project/rspec/storage_spec.rb
66
67
  - test_project/test_project.rb
67
68
  - COPYING
68
69
  - README
@@ -1,7 +0,0 @@
1
- module Synthesis
2
- class ExpectationsAdapter < Adapter
3
- def run
4
- fail_unless { Expectations::SuiteRunner.instance.suite.execute }
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module Expectations
2
- class SuiteRunner
3
- def initialize
4
- self.suite = Expectations::Suite.new
5
- end
6
- end
7
- end
@@ -1,17 +0,0 @@
1
- module Mocha
2
- class ClassMethod
3
- alias mocha_stub stub
4
-
5
- def stub
6
- @stubbee.mocked!
7
- mocha_stub
8
- end
9
-
10
- alias mocha_unstub unstub
11
-
12
- def unstub
13
- mocha_unstub
14
- @stubbee.unmocked!
15
- end
16
- end
17
- end
@@ -1,12 +0,0 @@
1
- module Synthesis
2
- class ExpectationRecord
3
- class << self
4
- alias_method :add_mocha_expectation, :add_expectation
5
-
6
- def add_expectation(obj, meth, track, args = [])
7
- # Ignone things like "foo = mock"
8
- add_mocha_expectation(obj, meth, track, args) unless obj.is_a?(Class::AnyInstance)
9
- end
10
- end
11
- end
12
- end
@@ -1,11 +0,0 @@
1
- module Synthesis
2
- class MethodInvocationWatcher
3
- class << self
4
- alias mocha_invoked invoked
5
-
6
- def invoked(receiver, method, args = [])
7
- mocha_invoked(receiver, method, args) unless receiver.mocked?
8
- end
9
- end
10
- end
11
- end
@@ -1,8 +0,0 @@
1
- module Synthesis
2
- class MochaAdapter < Adapter
3
- def run
4
- Test::Unit.run = true # Yes means no...
5
- fail_unless { Test::Unit::AutoRunner.run }
6
- end
7
- end
8
- end
@@ -1,12 +0,0 @@
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
@@ -1,22 +0,0 @@
1
- class Object
2
- alias mocha_expects expects
3
-
4
- def expects(meth)
5
- s_expectation = Synthesis::ExpectationRecord.add_expectation(self, meth, caller[0])
6
- m_expectation = mocha_expects(meth)
7
- m_expectation.synthesis_expectation = s_expectation
8
- m_expectation
9
- end
10
-
11
- def mocked!
12
- @mocked = true
13
- end
14
-
15
- def unmocked!
16
- @mocked = false
17
- end
18
-
19
- def mocked?
20
- @mocked
21
- end
22
- end
@@ -1,29 +0,0 @@
1
- %w(test/unit rubygems mocha).each { |l| require l }
2
- require File.dirname(__FILE__) + "/../../../../lib/synthesis/adapter/mocha"
3
-
4
- module Synthesis
5
- class MethodInvocationWatcherTest < Test::Unit::TestCase
6
- def teardown
7
- ExpectationRecord.expectations.clear
8
- end
9
-
10
- def test_ignores_invocation_for_mocked_object
11
- foo = Class.new { def self.bar;end }
12
- ExpectationRecord.add_expectation foo, :bar, :track
13
- ExpectationRecord.record_invocations
14
- e = ExpectationRecord.expectations.to_a[0]
15
- foo.expects(:bar)
16
- foo.bar
17
- assert !e.invoked?
18
- end
19
-
20
- def test_records_invocation_for_non_mocked_object
21
- foo = Class.new { def self.bar;end }
22
- ExpectationRecord.add_expectation foo, :bar, :track
23
- ExpectationRecord.record_invocations
24
- e = ExpectationRecord.expectations.to_a[0]
25
- foo.bar
26
- assert e.invoked?
27
- end
28
- end
29
- end