mocha 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,9 +8,6 @@ require 'mocha/mock_methods_test'
8
8
  require 'mocha/mock_test'
9
9
  require 'mocha/auto_verify_test'
10
10
 
11
- require 'auto_mocha/mock_class_test'
12
- require 'auto_mocha/auto_mock_test'
13
-
14
11
  require 'stubba/central_test'
15
12
  require 'stubba/class_method_test'
16
13
  require 'stubba/instance_method_test'
@@ -31,8 +28,6 @@ class UnitTests
31
28
  suite << MockMethodsTest.suite
32
29
  suite << MockTest.suite
33
30
  suite << AutoVerifyTest.suite
34
- suite << MockClassTest.suite
35
- suite << AutoMockTest.suite
36
31
  suite << CentralTest.suite
37
32
  suite << ClassMethodTest.suite
38
33
  suite << InstanceMethodTest.suite
@@ -65,7 +60,6 @@ end
65
60
  Test::Unit::UI::Console::TestRunner.run(IntegrationTests)
66
61
 
67
62
  require 'mocha_acceptance_test'
68
- require 'auto_mock_acceptance_test'
69
63
  require 'stubba_acceptance_test'
70
64
 
71
65
  class AcceptanceTests
@@ -73,7 +67,6 @@ class AcceptanceTests
73
67
  def self.suite
74
68
  suite = Test::Unit::TestSuite.new('AcceptanceTests')
75
69
  suite << MochaAcceptanceTest.suite
76
- suite << AutoMockAcceptanceTest.suite
77
70
  suite << StubbaAcceptanceTest.suite
78
71
  suite
79
72
  end
@@ -10,7 +10,7 @@ class AutoVerifyTest < Test::Unit::TestCase
10
10
  @test_case = Object.new
11
11
  class << test_case
12
12
  def self.add_teardown_method(symbol); end
13
- include AutoVerify
13
+ include Mocha::AutoVerify
14
14
  end
15
15
  end
16
16
 
@@ -146,4 +146,19 @@ class AutoVerifyTest < Test::Unit::TestCase
146
146
  assert_equal [greedy_stub], test_case.mocks
147
147
  end
148
148
 
149
+ def test_should_create_mock_with_name
150
+ mock = test_case.mock('named_mock')
151
+ assert_equal 'named_mock', mock.__mock_name
152
+ end
153
+
154
+ def test_should_create_stub_with_name
155
+ stub = test_case.stub('named_stub')
156
+ assert_equal 'named_stub', stub.__mock_name
157
+ end
158
+
159
+ def test_should_create_greedy_stub_with_name
160
+ greedy_stub = test_case.stub_everything('named_greedy_stub')
161
+ assert_equal 'named_greedy_stub', greedy_stub.__mock_name
162
+ end
163
+
149
164
  end
@@ -252,28 +252,30 @@ class ExpectationSimilarExpectationsTest < Test::Unit::TestCase
252
252
  attr_reader :expectation
253
253
  def setup
254
254
  @expectation = Expectation.new(:meth).with(2)
255
+ @mock = Object.new
255
256
  end
256
257
 
257
258
  def test_should_find_expectations_to_the_same_method
258
- failed_expectation = MissingExpectation.new(:meth, [expectation]).with(1)
259
+ failed_expectation = MissingExpectation.new(:meth, @mock, [expectation]).with(1)
259
260
  assert_equal [expectation], failed_expectation.similar_expectations
260
261
  end
261
262
 
262
263
  def test_should_report_similar_expectations
263
- missing_expectation = MissingExpectation.new(:meth, [expectation]).with(1)
264
+ missing_expectation = MissingExpectation.new(:meth, @mock, [expectation]).with(1)
264
265
  exception = assert_raise(Test::Unit::AssertionFailedError) { missing_expectation.verify }
265
- assert_equal "Unexpected message :meth(1)\nSimilar expectations :meth(2)", exception.message
266
+ assert_equal "Unexpected message :meth(1) sent to #{@mock.mocha_inspect}\nSimilar expectations :meth(2)", exception.message
266
267
  end
267
268
 
268
269
  def test_should_ignore_expectations_to_different_methods
269
- failed_expectation = MissingExpectation.new(:other_meth, [expectation]).with(1)
270
+ failed_expectation = MissingExpectation.new(:other_meth, @mock, [expectation]).with(1)
270
271
  assert failed_expectation.similar_expectations.empty?
271
272
  end
272
273
 
273
274
  def test_should_not_report_similar_expectations
274
- missing_expectation = MissingExpectation.new(:other_meth, [expectation]).with(1)
275
+ missing_expectation = MissingExpectation.new(:other_meth, @mock, [expectation]).with(1)
275
276
  exception = assert_raise(Test::Unit::AssertionFailedError) { missing_expectation.verify }
276
- assert_equal "Unexpected message :other_meth(1)", exception.message
277
+ assert_equal "Unexpected message :other_meth(1) sent to #{@mock.mocha_inspect}", exception.message
278
+ p exception.message
277
279
  end
278
280
 
279
281
  end
@@ -138,7 +138,7 @@ class MockMethodsTest < Test::Unit::TestCase
138
138
  mock = Object.new.extend(MockMethods)
139
139
  mock.expects(:meth).with(1)
140
140
  exception = assert_raise(Test::Unit::AssertionFailedError) { mock.meth(2) }
141
- assert_equal "Unexpected message :meth(2)\nSimilar expectations :meth(1)", exception.message
141
+ assert_equal "Unexpected message :meth(2) sent to #{mock.mocha_inspect}\nSimilar expectations :meth(1)", exception.message
142
142
  end
143
143
 
144
144
  def test_should_pass_block_through_to_expectations_verify_method
@@ -34,4 +34,14 @@ class MockTest < Test::Unit::TestCase
34
34
  assert_equal true, mock.stub_everything
35
35
  end
36
36
 
37
+ def test_should_use_default_inspect_message
38
+ mock = Mock.new
39
+ assert_equal mock.mocha_inspect_before_hijacked_by_named_mocks, mock.mocha_inspect
40
+ end
41
+
42
+ def test_should_give_name_in_inspect_message
43
+ mock = Mock.new(false, 'named_mock')
44
+ assert_equal "#<Mock: 'named_mock'>", mock.mocha_inspect
45
+ end
46
+
37
47
  end
@@ -94,8 +94,8 @@ class MochaTestResultIntegrationTest < Test::Unit::TestCase
94
94
 
95
95
  def run_test(test_result = Test::Unit::TestResult.new, &block)
96
96
  test_class = Class.new(Test::Unit::TestCase) do
97
- include MultipleSetupAndTeardown
98
- include AutoVerify
97
+ include SmartTestCase::MultipleSetupAndTeardown
98
+ include Mocha::AutoVerify
99
99
  define_method(:test_me, &block)
100
100
  end
101
101
  test = test_class.new(:test_me)
@@ -7,7 +7,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
7
7
  def test_should_call_added_setup
8
8
  test_case = Class.new(Test::Unit::TestCase) do
9
9
  define_method(:methods_called) { @methods_called ||= [] }
10
- include MultipleSetupAndTeardown
10
+ include SmartTestCase::MultipleSetupAndTeardown
11
11
  add_setup_method(:added_setup)
12
12
  define_method(:added_setup) { methods_called << :added_setup }
13
13
  define_method(:test_method) { methods_called << :test_method }
@@ -22,7 +22,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
22
22
  def test_should_call_added_teardown
23
23
  test_case = Class.new(Test::Unit::TestCase) do
24
24
  define_method(:methods_called) { @methods_called ||= [] }
25
- include MultipleSetupAndTeardown
25
+ include SmartTestCase::MultipleSetupAndTeardown
26
26
  add_teardown_method(:added_teardown)
27
27
  define_method(:added_teardown) { methods_called << :added_teardown }
28
28
  define_method(:test_method) { methods_called << :test_method }
@@ -37,7 +37,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
37
37
  def test_should_call_both_added_teardowns_even_if_one_raises_exception
38
38
  test_case = Class.new(Test::Unit::TestCase) do
39
39
  define_method(:methods_called) { @methods_called ||= [] }
40
- include MultipleSetupAndTeardown
40
+ include SmartTestCase::MultipleSetupAndTeardown
41
41
  add_teardown_method(:added_teardown_1)
42
42
  add_teardown_method(:added_teardown_2)
43
43
  define_method(:added_teardown_1) { methods_called << :added_teardown_1 }
@@ -55,7 +55,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
55
55
  test_case = Class.new(Test::Unit::TestCase) do
56
56
  define_method(:methods_called) { @methods_called ||= [] }
57
57
  define_method(:setup) { methods_called << :setup }
58
- include MultipleSetupAndTeardown
58
+ include SmartTestCase::MultipleSetupAndTeardown
59
59
  add_setup_method(:added_setup)
60
60
  define_method(:added_setup) { methods_called << :added_setup }
61
61
  define_method(:test_method) { methods_called << :test_method }
@@ -71,7 +71,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
71
71
  test_case = Class.new(Test::Unit::TestCase) do
72
72
  define_method(:methods_called) { @methods_called ||= [] }
73
73
  define_method(:teardown) { methods_called << :teardown }
74
- include MultipleSetupAndTeardown
74
+ include SmartTestCase::MultipleSetupAndTeardown
75
75
  add_teardown_method(:added_teardown)
76
76
  define_method(:added_teardown) { methods_called << :added_teardown }
77
77
  define_method(:test_method) { methods_called << :test_method }
@@ -86,7 +86,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
86
86
  def test_should_call_added_setup_and_setup_defined_after_module_included
87
87
  test_case = Class.new(Test::Unit::TestCase) do
88
88
  define_method(:methods_called) { @methods_called ||= [] }
89
- include MultipleSetupAndTeardown
89
+ include SmartTestCase::MultipleSetupAndTeardown
90
90
  define_method(:setup) { methods_called << :setup }
91
91
  add_setup_method(:added_setup)
92
92
  define_method(:added_setup) { methods_called << :added_setup }
@@ -102,7 +102,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
102
102
  def test_should_call_added_teardown_and_teardown_defined_after_module_included
103
103
  test_case = Class.new(Test::Unit::TestCase) do
104
104
  define_method(:methods_called) { @methods_called ||= [] }
105
- include MultipleSetupAndTeardown
105
+ include SmartTestCase::MultipleSetupAndTeardown
106
106
  define_method(:teardown) { methods_called << :teardown }
107
107
  add_teardown_method(:added_teardown)
108
108
  define_method(:added_teardown) { methods_called << :added_teardown }
@@ -118,7 +118,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
118
118
  def test_should_call_added_setup_and_setup_defined_in_derived_test_case
119
119
  test_case = Class.new(Test::Unit::TestCase) do
120
120
  define_method(:methods_called) { @methods_called ||= [] }
121
- include MultipleSetupAndTeardown
121
+ include SmartTestCase::MultipleSetupAndTeardown
122
122
  add_setup_method(:added_setup)
123
123
  define_method(:added_setup) { methods_called << :added_setup }
124
124
  end
@@ -136,7 +136,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
136
136
  def test_should_call_added_teardown_and_teardown_defined_in_derived_test_case
137
137
  test_case = Class.new(Test::Unit::TestCase) do
138
138
  define_method(:methods_called) { @methods_called ||= [] }
139
- include MultipleSetupAndTeardown
139
+ include SmartTestCase::MultipleSetupAndTeardown
140
140
  add_teardown_method(:added_teardown)
141
141
  define_method(:added_teardown) { methods_called << :added_teardown }
142
142
  end
@@ -155,7 +155,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
155
155
  test_case = Class.new(Test::Unit::TestCase) do
156
156
  define_method(:methods_called) { @methods_called ||= [] }
157
157
  include ActiveRecordTestCase
158
- include MultipleSetupAndTeardown
158
+ include SmartTestCase::MultipleSetupAndTeardown
159
159
  add_setup_method(:added_setup)
160
160
  define_method(:added_setup) { methods_called << :added_setup }
161
161
  end
@@ -174,7 +174,7 @@ class MultipleSetupAndTeardownTest < Test::Unit::TestCase
174
174
  test_case = Class.new(Test::Unit::TestCase) do
175
175
  define_method(:methods_called) { @methods_called ||= [] }
176
176
  include ActiveRecordTestCase
177
- include MultipleSetupAndTeardown
177
+ include SmartTestCase::MultipleSetupAndTeardown
178
178
  add_teardown_method(:added_teardown)
179
179
  define_method(:added_teardown) { methods_called << :added_teardown }
180
180
  end
@@ -14,7 +14,7 @@ class SetupAndTeardownTest < Test::Unit::TestCase
14
14
  define_method(:add_setup_method) { |symbol| @symbol = symbol }
15
15
  define_method(:add_teardown_method) {}
16
16
  end
17
- include SetupAndTeardown
17
+ include Stubba::SetupAndTeardown
18
18
  end
19
19
 
20
20
  assert_equal :setup_stubs, test_case_class.symbol
@@ -27,7 +27,7 @@ class SetupAndTeardownTest < Test::Unit::TestCase
27
27
  define_method(:add_setup_method) {}
28
28
  define_method(:add_teardown_method) { |symbol| @symbol = symbol }
29
29
  end
30
- include SetupAndTeardown
30
+ include Stubba::SetupAndTeardown
31
31
  end
32
32
 
33
33
  assert_equal :teardown_stubs, test_case_class.symbol
@@ -126,7 +126,7 @@ class SetupAndTeardownTest < Test::Unit::TestCase
126
126
  end
127
127
  attr_accessor :add_assertion_called
128
128
  define_method(:add_assertion) { self.add_assertion_called = true }
129
- include SetupAndTeardown
129
+ include Stubba::SetupAndTeardown
130
130
  end
131
131
  end
132
132
 
@@ -11,11 +11,11 @@ class StubbaIntegrationTest < Test::Unit::TestCase
11
11
  :original_return_value
12
12
  end
13
13
  end
14
-
14
+
15
15
  def test_should_stub_class_method_within_test
16
16
  test_class = Class.new(Test::Unit::TestCase) do
17
- include MultipleSetupAndTeardown
18
- include SetupAndTeardown
17
+ include SmartTestCase::MultipleSetupAndTeardown
18
+ include Stubba::SetupAndTeardown
19
19
  define_method(:test_me) do
20
20
  DontMessWithMe.expects(:method_x).returns(:new_return_value)
21
21
  assert_equal :new_return_value, DontMessWithMe.method_x
@@ -30,8 +30,8 @@ class StubbaIntegrationTest < Test::Unit::TestCase
30
30
 
31
31
  def test_should_leave_stubbed_class_unchanged_after_test
32
32
  test_class = Class.new(Test::Unit::TestCase) do
33
- include MultipleSetupAndTeardown
34
- include SetupAndTeardown
33
+ include SmartTestCase::MultipleSetupAndTeardown
34
+ include Stubba::SetupAndTeardown
35
35
  define_method(:test_me) do
36
36
  DontMessWithMe.expects(:method_x).returns(:new_return_value)
37
37
  end
@@ -44,8 +44,8 @@ class StubbaIntegrationTest < Test::Unit::TestCase
44
44
 
45
45
  def test_should_reset_expectations_after_test
46
46
  test_class = Class.new(Test::Unit::TestCase) do
47
- include MultipleSetupAndTeardown
48
- include SetupAndTeardown
47
+ include SmartTestCase::MultipleSetupAndTeardown
48
+ include Stubba::SetupAndTeardown
49
49
  define_method(:test_me) do
50
50
  DontMessWithMe.expects(:method_x)
51
51
  end
@@ -74,8 +74,8 @@ class StubbaTestResultIntegrationTest < Test::Unit::TestCase
74
74
 
75
75
  def run_test(test_result = Test::Unit::TestResult.new, &block)
76
76
  test_class = Class.new(Test::Unit::TestCase) do
77
- include MultipleSetupAndTeardown
78
- include SetupAndTeardown
77
+ include SmartTestCase::MultipleSetupAndTeardown
78
+ include Stubba::SetupAndTeardown
79
79
  define_method(:test_me, &block)
80
80
  end
81
81
  test = test_class.new(:test_me)
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.3.1
7
- date: 2006-08-30 00:00:00 +01:00
6
+ version: 0.3.2
7
+ date: 2006-09-06 00:00:00 +01:00
8
8
  summary: Mocking and stubbing library
9
9
  require_paths:
10
10
  - lib
@@ -12,9 +12,7 @@ email: mocha-developer@rubyforge.org
12
12
  homepage: http://mocha.rubyforge.org
13
13
  rubyforge_project: mocha
14
14
  description: "Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and
15
- stubbing of methods on real (non-mock) classes. Includes auto-mocking which
16
- magically provides mocks for undefined classes, facilitating unit tests with no
17
- external dependencies."
15
+ stubbing of methods on real (non-mock) classes."
18
16
  autorequire: mocha
19
17
  default_executable:
20
18
  bindir: bin
@@ -32,12 +30,9 @@ cert_chain:
32
30
  authors:
33
31
  - James Mead
34
32
  files:
35
- - lib/auto_mocha.rb
36
33
  - lib/mocha.rb
37
34
  - lib/smart_test_case.rb
38
35
  - lib/stubba.rb
39
- - lib/auto_mocha/auto_mock.rb
40
- - lib/auto_mocha/mock_class.rb
41
36
  - lib/mocha/auto_verify.rb
42
37
  - lib/mocha/expectation.rb
43
38
  - lib/mocha/infinite_range.rb
@@ -56,7 +51,6 @@ files:
56
51
  - lib/stubba/setup_and_teardown.rb
57
52
  - test/active_record_test_case.rb
58
53
  - test/all_tests.rb
59
- - test/auto_mock_acceptance_test.rb
60
54
  - test/execution_point.rb
61
55
  - test/method_definer.rb
62
56
  - test/mocha_acceptance_test.rb
@@ -65,8 +59,6 @@ files:
65
59
  - test/stubba_integration_test.rb
66
60
  - test/stubba_test_result_integration_test.rb
67
61
  - test/test_helper.rb
68
- - test/auto_mocha/auto_mock_test.rb
69
- - test/auto_mocha/mock_class_test.rb
70
62
  - test/mocha/auto_verify_test.rb
71
63
  - test/mocha/expectation_test.rb
72
64
  - test/mocha/infinite_range_test.rb
@@ -86,7 +78,6 @@ files:
86
78
  - Rakefile
87
79
  - README
88
80
  - RELEASE
89
- - TODO
90
81
  test_files:
91
82
  - test/all_tests.rb
92
83
  rdoc_options:
data/TODO DELETED
@@ -1,14 +0,0 @@
1
- - think about behaviour when more than one expectation/stubbed method match
2
- - make verify method private (makes this unnecessary - fail if attempt to verify stub)
3
- - allow hash parameter for stubs and expects methods particularly for stubba
4
- - write rdoc for most important methods/classes e.g. expectation
5
- - test for setting expectations on class methods (and instance methods?) from within TestCase#setup
6
- - use Object#inspect(:mocha) instead of Object#mocha_inspect?
7
- - allow stubbing of private/protected methods?
8
- - should all instances share expectations for any_instance or should each instance have their own - in which case how do we provide access to the instances
9
- - detect existing or added definition of mocha methods e.g. expects and alias to __expects?
10
- - allow switch off of auto-verify?
11
- - maybe use blank_slate as mocha parent class to allow mocking of standard object methods?
12
- - more jmock style stuff - e.g. return values on consecutive calls, labels/required order, more sophisticated param matching?
13
- - stubs should only return a fixed value - no blocks allowed for return values and no parameter expectations allowed?
14
- - maybe allow unstubbing of a specific method from within a test...?
@@ -1,2 +0,0 @@
1
- require 'mocha'
2
- require 'auto_mocha/auto_mock'
@@ -1,54 +0,0 @@
1
- require 'auto_mocha/mock_class'
2
-
3
- class Module
4
-
5
- def mochas
6
- @@mochas ||= {}
7
- end
8
-
9
- def reset_mochas
10
- @@mochas = nil
11
- end
12
-
13
- def const_missing(symbol)
14
- mochas[symbol] ||= Mocha::MockClass.dup
15
- end
16
-
17
- def verify_all
18
- mochas.each_value { |mocha| mocha.verify_all }
19
- end
20
-
21
- end
22
-
23
- Mocha::MockClass.class_eval do
24
-
25
- class << self
26
-
27
- def mochas
28
- @mochas ||= {}
29
- end
30
-
31
- def const_missing(symbol)
32
- mochas[symbol] ||= Mocha::MockClass.dup
33
- end
34
-
35
- def verify_all
36
- mochas.each_value { |mocha| mocha.verify }
37
- verify
38
- end
39
-
40
- end
41
-
42
- end
43
-
44
- class Test::Unit::TestCase
45
-
46
- def reset_mochas
47
- Object.reset_mochas
48
- end
49
-
50
- def verify_all
51
- Object.verify_all
52
- end
53
-
54
- end
@@ -1,38 +0,0 @@
1
- require 'mocha/mock_methods'
2
-
3
- module Mocha
4
-
5
- class MockClass
6
-
7
- include MockMethods
8
-
9
- class << self
10
-
11
- include MockMethods
12
-
13
- def super_method_missing(symbol, *arguments, &block)
14
- superclass.method_missing(symbol, *arguments, &block)
15
- end
16
-
17
- alias_method :__new__, :new
18
-
19
- def new(*arguments, &block)
20
- method_missing(:new, *arguments, &block)
21
- end
22
-
23
- def inherited(subclass)
24
- subclass.class_eval do
25
-
26
- def self.new(*arguments, &block)
27
- __new__(*arguments, &block)
28
- end
29
-
30
- end
31
-
32
- end
33
-
34
- end
35
-
36
- end
37
-
38
- end