mocha 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,12 @@
1
1
  require File.join(File.dirname(__FILE__), "..", "test_helper")
2
- require 'stubba_replacer'
2
+ require 'mocha/mock'
3
3
 
4
4
  require 'stubba/object'
5
5
 
6
6
  class ObjectTest < Test::Unit::TestCase
7
7
 
8
- include Stubba
9
8
  include Mocha
10
-
9
+
11
10
  def test_should_build_mocha
12
11
  instance = Object.new
13
12
  mocha = instance.mocha
@@ -29,29 +28,23 @@ class ObjectTest < Test::Unit::TestCase
29
28
 
30
29
  def test_should_stub_instance_method
31
30
  instance = Object.new
32
- stubba = Mock.new
33
- stubba.expects(:stub).with(InstanceMethod.new(instance, :method1))
34
- replace_stubba(stubba) do
35
- instance.expects(:method1)
36
- end
37
- stubba.verify(:stub)
31
+ $stubba = Mock.new
32
+ $stubba.expects(:stub).with(Stubba::InstanceMethod.new(instance, :method1))
33
+ instance.expects(:method1)
34
+ $stubba.verify(:stub)
38
35
  end
39
36
 
40
37
  def test_should_build_and_store_expectation
41
38
  instance = Object.new
42
- stubba = Mock.new(:stub => nil)
43
- replace_stubba(stubba) do
44
- expectation = instance.expects(:method1)
45
- assert_equal [expectation], instance.mocha.expectations
46
- end
39
+ $stubba = Mock.new(:stub => nil)
40
+ expectation = instance.expects(:method1)
41
+ assert_equal [expectation], instance.mocha.expectations
47
42
  end
48
43
 
49
44
  def test_should_verify_expectations
50
45
  instance = Object.new
51
- stubba = Mock.new(:stub => nil)
52
- replace_stubba(stubba) do
53
- instance.expects(:method1).with(:value1, :value2)
54
- end
46
+ $stubba = Mock.new(:stub => nil)
47
+ instance.expects(:method1).with(:value1, :value2)
55
48
  assert_raise(Test::Unit::AssertionFailedError) { instance.verify }
56
49
  end
57
50
 
@@ -71,56 +64,48 @@ class ObjectTest < Test::Unit::TestCase
71
64
 
72
65
  def test_should_stub_class_method
73
66
  klass = Class.new
74
- stubba = Mock.new
75
- stubba.expects(:stub).with(ClassMethod.new(klass, :method1))
76
- replace_stubba(stubba) do
77
- klass.expects(:method1)
78
- end
79
- stubba.verify(:stub)
67
+ $stubba = Mock.new
68
+ $stubba.expects(:stub).with(Stubba::ClassMethod.new(klass, :method1))
69
+ klass.expects(:method1)
70
+ $stubba.verify(:stub)
80
71
  end
81
72
 
82
73
  def test_should_build_and_store_class_method_expectation
83
74
  klass = Class.new
84
- stubba = Mock.new(:stub => nil)
85
- replace_stubba(stubba) do
86
- expectation = klass.expects(:method1)
87
- assert_equal [expectation], klass.mocha.expectations
88
- end
75
+ $stubba = Mock.new(:stub => nil)
76
+ expectation = klass.expects(:method1)
77
+ assert_equal [expectation], klass.mocha.expectations
89
78
  end
90
79
 
91
80
  def test_should_stub_module_method
92
81
  mod = Module.new
93
- stubba = Mock.new
94
- stubba.expects(:stub).with(ClassMethod.new(mod, :method1))
95
- replace_stubba(stubba) do
96
- mod.expects(:method1)
97
- end
98
- stubba.verify(:stub)
82
+ $stubba = Mock.new
83
+ $stubba.expects(:stub).with(Stubba::ClassMethod.new(mod, :method1))
84
+ mod.expects(:method1)
85
+ $stubba.verify(:stub)
99
86
  end
100
87
 
101
88
  def test_should_build_and_store_module_method_expectation
102
89
  mod = Module.new
103
- stubba = Mock.new(:stub => nil)
104
- replace_stubba(stubba) do
105
- expectation = mod.expects(:method1)
106
- assert_equal [expectation], mod.mocha.expectations
107
- end
90
+ $stubba = Mock.new(:stub => nil)
91
+ expectation = mod.expects(:method1)
92
+ assert_equal [expectation], mod.mocha.expectations
108
93
  end
109
94
 
110
95
  def test_should_use_stubba_instance_method_for_object
111
- assert_equal InstanceMethod, Object.new.stubba_method
96
+ assert_equal Stubba::InstanceMethod, Object.new.stubba_method
112
97
  end
113
98
 
114
99
  def test_should_use_stubba_class_method_for_module
115
- assert_equal ClassMethod, Module.new.stubba_method
100
+ assert_equal Stubba::ClassMethod, Module.new.stubba_method
116
101
  end
117
102
 
118
103
  def test_should_use_stubba_class_method_for_class
119
- assert_equal ClassMethod, Class.new.stubba_method
104
+ assert_equal Stubba::ClassMethod, Class.new.stubba_method
120
105
  end
121
106
 
122
107
  def test_should_use_stubba_class_method_for_any_instance
123
- assert_equal AnyInstanceMethod, Class::AnyInstance.new(nil).stubba_method
108
+ assert_equal Stubba::AnyInstanceMethod, Class::AnyInstance.new(nil).stubba_method
124
109
  end
125
110
 
126
111
  def test_should_stub_self_for_object
@@ -0,0 +1,76 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+ require 'mocha/mock'
3
+
4
+ require 'stubba/setup_and_teardown'
5
+
6
+ class SetupAndTeardownTest < Test::Unit::TestCase
7
+
8
+ include Mocha
9
+
10
+ def test_should_add_setup_stubs_to_setup_methods
11
+ test_case_class = Class.new do
12
+ class << self
13
+ attr_accessor :symbol
14
+ define_method(:add_setup_method) { |symbol| @symbol = symbol }
15
+ define_method(:add_teardown_method) {}
16
+ end
17
+ include SetupAndTeardown
18
+ end
19
+
20
+ assert_equal :setup_stubs, test_case_class.symbol
21
+ end
22
+
23
+ def test_should_add_teardown_stubs_to_teardown_methods
24
+ test_case_class = Class.new do
25
+ class << self
26
+ attr_accessor :symbol
27
+ define_method(:add_setup_method) {}
28
+ define_method(:add_teardown_method) { |symbol| @symbol = symbol }
29
+ end
30
+ include SetupAndTeardown
31
+ end
32
+
33
+ assert_equal :teardown_stubs, test_case_class.symbol
34
+ end
35
+
36
+ def test_should_instantiate_new_stubba
37
+ test_case = stubbed_test_case_class.new
38
+ test_case.setup_stubs
39
+
40
+ assert $stubba
41
+ assert $stubba.is_a?(Stubba::Central)
42
+ end
43
+
44
+ def test_should_unstub_all_stubbed_methods
45
+ test_case = stubbed_test_case_class.new
46
+ stubba = Mock.new(:unstub_all => nil)
47
+ $stubba = stubba
48
+
49
+ test_case.teardown_stubs
50
+
51
+ stubba.verify
52
+ end
53
+
54
+ def test_should_set_stubba_to_nil
55
+ test_case = stubbed_test_case_class.new
56
+ $stubba = Mock.new(:unstub_all => nil)
57
+
58
+ test_case.teardown_stubs
59
+
60
+ assert_nil $stubba
61
+ end
62
+
63
+ private
64
+
65
+ def stubbed_test_case_class
66
+ Class.new do
67
+ class << self
68
+ define_method(:add_setup_method) {}
69
+ define_method(:add_teardown_method) {}
70
+ end
71
+ include SetupAndTeardown
72
+ end
73
+ end
74
+
75
+ end
76
+
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
- require 'stubba_replacer'
3
2
 
4
3
  require 'stubba/object'
5
- require 'stubba/test_case'
4
+ require 'smart_test_case/multiple_setup_and_teardown'
5
+ require 'stubba/setup_and_teardown'
6
6
 
7
7
  class StubbaIntegrationTest < Test::Unit::TestCase
8
8
 
@@ -14,45 +14,45 @@ class StubbaIntegrationTest < Test::Unit::TestCase
14
14
 
15
15
  def test_should_stub_class_method_within_test
16
16
  test_class = Class.new(Test::Unit::TestCase) do
17
- def test_me
17
+ include MultipleSetupAndTeardown
18
+ include SetupAndTeardown
19
+ define_method(:test_me) do
18
20
  DontMessWithMe.expects(:method_x).returns(:new_return_value)
19
21
  assert_equal :new_return_value, DontMessWithMe.method_x
20
22
  end
21
23
  end
22
24
  test = test_class.new(:test_me)
23
25
 
24
- replace_stubba(nil) do
25
- test_result = Test::Unit::TestResult.new
26
- test.run(test_result) {}
27
- assert test_result.passed?
28
- end
26
+ test_result = Test::Unit::TestResult.new
27
+ test.run(test_result) {}
28
+ assert test_result.passed?
29
29
  end
30
30
 
31
31
  def test_should_leave_stubbed_class_unchanged_after_test
32
32
  test_class = Class.new(Test::Unit::TestCase) do
33
- def test_me
33
+ include MultipleSetupAndTeardown
34
+ include SetupAndTeardown
35
+ define_method(:test_me) do
34
36
  DontMessWithMe.expects(:method_x).returns(:new_return_value)
35
37
  end
36
38
  end
37
39
  test = test_class.new(:test_me)
38
40
 
39
- replace_stubba(nil) do
40
- test.run(Test::Unit::TestResult.new) {}
41
- assert_equal :original_return_value, DontMessWithMe.method_x
42
- end
41
+ test.run(Test::Unit::TestResult.new) {}
42
+ assert_equal :original_return_value, DontMessWithMe.method_x
43
43
  end
44
44
 
45
45
  def test_should_reset_expectations_after_test
46
46
  test_class = Class.new(Test::Unit::TestCase) do
47
- def test_me
47
+ include MultipleSetupAndTeardown
48
+ include SetupAndTeardown
49
+ define_method(:test_me) do
48
50
  DontMessWithMe.expects(:method_x)
49
51
  end
50
52
  end
51
53
  test = test_class.new(:test_me)
52
54
 
53
- replace_stubba(nil) do
54
- test.run(Test::Unit::TestResult.new) {}
55
- end
55
+ test.run(Test::Unit::TestResult.new) {}
56
56
  assert_equal 0, DontMessWithMe.mocha.expectations.size
57
57
  end
58
58
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: mocha
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2006-07-16 00:00:00 +01:00
6
+ version: 0.2.0
7
+ date: 2006-08-11 00:00:00 +01:00
8
8
  summary: Mocking and stubbing library
9
9
  require_paths:
10
10
  - lib
@@ -34,9 +34,11 @@ authors:
34
34
  files:
35
35
  - lib/auto_mocha.rb
36
36
  - lib/mocha.rb
37
+ - lib/smart_test_case.rb
37
38
  - lib/stubba.rb
38
39
  - lib/auto_mocha/auto_mock.rb
39
40
  - lib/auto_mocha/mock_class.rb
41
+ - lib/mocha/auto_verify.rb
40
42
  - lib/mocha/expectation.rb
41
43
  - lib/mocha/infinite_range.rb
42
44
  - lib/mocha/inspect.rb
@@ -44,37 +46,41 @@ files:
44
46
  - lib/mocha/mock.rb
45
47
  - lib/mocha/mock_methods.rb
46
48
  - lib/mocha/pretty_parameters.rb
49
+ - lib/smart_test_case/multiple_setup_and_teardown.rb
47
50
  - lib/stubba/any_instance_method.rb
51
+ - lib/stubba/central.rb
48
52
  - lib/stubba/class_method.rb
49
53
  - lib/stubba/instance_method.rb
50
54
  - lib/stubba/object.rb
51
- - lib/stubba/stubba.rb
52
- - lib/stubba/test_case.rb
55
+ - lib/stubba/setup_and_teardown.rb
56
+ - test/active_record_test_case.rb
53
57
  - test/all_tests.rb
54
58
  - test/auto_mock_acceptance_test.rb
55
59
  - test/method_definer.rb
56
60
  - test/mocha_acceptance_test.rb
57
61
  - test/stubba_acceptance_test.rb
58
62
  - test/stubba_integration_test.rb
59
- - test/stubba_replacer.rb
60
63
  - test/test_helper.rb
61
64
  - test/auto_mocha/auto_mock_test.rb
62
65
  - test/auto_mocha/mock_class_test.rb
66
+ - test/mocha/auto_verify_test.rb
63
67
  - test/mocha/expectation_test.rb
64
68
  - test/mocha/infinite_range_test.rb
65
69
  - test/mocha/inspect_test.rb
66
70
  - test/mocha/mock_methods_test.rb
67
71
  - test/mocha/mock_test.rb
68
72
  - test/mocha/pretty_parameters_test.rb
73
+ - test/smart_test_case/multiple_setup_and_teardown_test.rb
69
74
  - test/stubba/any_instance_method_test.rb
75
+ - test/stubba/central_test.rb
70
76
  - test/stubba/class_method_test.rb
71
77
  - test/stubba/instance_method_test.rb
72
78
  - test/stubba/object_test.rb
73
- - test/stubba/stubba_test.rb
74
- - test/stubba/test_case_test.rb
79
+ - test/stubba/setup_and_teardown_test.rb
75
80
  - COPYING
76
81
  - Rakefile
77
82
  - README
83
+ - RELEASE
78
84
  - TODO
79
85
  test_files:
80
86
  - test/all_tests.rb
@@ -1,65 +0,0 @@
1
- require 'stubba/stubba'
2
-
3
- class Test::Unit::TestCase
4
-
5
- def self.method_added(method)
6
- # disable until we finish messing about
7
- end
8
-
9
- def setup_with_stubba
10
- $stubba = Stubba::Stubba.new
11
- end
12
-
13
- def teardown_with_stubba
14
- $stubba.unstub_all
15
- $stubba = nil
16
- end
17
-
18
- if method_defined?(:setup) then
19
- alias_method :setup_pre_stubba, :setup
20
- define_method(:setup_post_stubba) do
21
- setup_pre_stubba
22
- setup_with_stubba
23
- end
24
- else
25
- define_method(:setup_post_stubba) do
26
- setup_with_stubba
27
- end
28
- end
29
- alias_method :setup, :setup_post_stubba
30
-
31
- if method_defined?(:teardown) then
32
- alias_method :teardown_pre_stubba, :teardown
33
- define_method(:teardown_post_stubba) do
34
- teardown_with_stubba
35
- teardown_pre_stubba
36
- end
37
- else
38
- define_method(:teardown_post_stubba) do
39
- teardown_with_stubba
40
- end
41
- end
42
- alias_method :teardown, :teardown_post_stubba
43
-
44
- def self.method_added(method)
45
- case method
46
- when :setup
47
- unless method_defined?(:setup_without_stubba)
48
- alias_method :setup_without_stubba, :setup
49
- define_method(:setup) do
50
- setup_post_stubba
51
- setup_without_stubba
52
- end
53
- end
54
- when :teardown
55
- unless method_defined?(:teardown_without_stubba)
56
- alias_method :teardown_without_stubba, :teardown
57
- define_method(:teardown) do
58
- teardown_without_stubba
59
- teardown_post_stubba
60
- end
61
- end
62
- end
63
- end
64
-
65
- end
@@ -1,41 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "test_helper")
2
- require 'stubba_replacer'
3
- require 'mocha/mock'
4
-
5
- require 'stubba/test_case'
6
-
7
- class TestCaseTest < Test::Unit::TestCase
8
-
9
- include Mocha
10
-
11
- def test_should_instantiate_new_stubba
12
- test_class = Class.new(Test::Unit::TestCase) { def test_me; end }
13
- test = test_class.new(:test_me)
14
- replace_stubba(nil) do
15
- test.setup
16
- assert $stubba.is_a?(Stubba::Stubba)
17
- end
18
- end
19
-
20
- def test_should_unstub_all_stubbed_methods
21
- test_class = Class.new(Test::Unit::TestCase) { def test_me; end }
22
- test = test_class.new(:test_me)
23
- stubba = Mock.new(:unstub_all => nil)
24
- replace_stubba(stubba) do
25
- test.teardown
26
- end
27
- stubba.verify(:unstub_all)
28
- end
29
-
30
- def test_should_set_stubba_to_nil
31
- test_class = Class.new(Test::Unit::TestCase) { def test_me; end }
32
- test = test_class.new(:test_me)
33
- stubba = Mock.new(:unstub_all => nil)
34
- replace_stubba(stubba) do
35
- test.teardown
36
- assert_nil $stubba
37
- end
38
- end
39
-
40
- end
41
-