mocha 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/README +4 -4
  2. data/RELEASE +32 -0
  3. data/Rakefile +3 -3
  4. data/examples/misc.rb +36 -0
  5. data/examples/mocha.rb +26 -0
  6. data/examples/stubba.rb +65 -0
  7. data/lib/mocha.rb +17 -5
  8. data/lib/{stubba → mocha}/any_instance_method.rb +2 -2
  9. data/lib/mocha/auto_verify.rb +7 -7
  10. data/lib/{stubba → mocha}/central.rb +2 -2
  11. data/lib/{stubba → mocha}/class_method.rb +7 -10
  12. data/lib/mocha/expectation.rb +88 -33
  13. data/lib/mocha/expectation_error.rb +6 -0
  14. data/lib/mocha/inspect.rb +1 -1
  15. data/lib/mocha/instance_method.rb +8 -0
  16. data/lib/mocha/metaclass.rb +1 -1
  17. data/lib/mocha/mock.rb +8 -8
  18. data/lib/mocha/mock_methods.rb +60 -16
  19. data/lib/{stubba → mocha}/object.rb +8 -10
  20. data/lib/mocha/setup_and_teardown.rb +23 -0
  21. data/lib/mocha/standalone.rb +30 -0
  22. data/lib/mocha/test_case_adapter.rb +49 -0
  23. data/lib/mocha_standalone.rb +2 -0
  24. data/lib/stubba.rb +2 -8
  25. data/test/all_tests.rb +9 -10
  26. data/test/method_definer.rb +2 -2
  27. data/test/{stubba → mocha}/any_instance_method_test.rb +1 -3
  28. data/test/mocha/auto_verify_test.rb +9 -10
  29. data/test/{stubba → mocha}/central_test.rb +5 -4
  30. data/test/{stubba → mocha}/class_method_test.rb +40 -10
  31. data/test/mocha/expectation_test.rb +144 -67
  32. data/test/mocha/inspect_test.rb +12 -1
  33. data/test/mocha/metaclass_test.rb +22 -0
  34. data/test/mocha/mock_methods_test.rb +65 -7
  35. data/test/mocha/mock_test.rb +41 -4
  36. data/test/{stubba → mocha}/object_test.rb +9 -9
  37. data/test/mocha/setup_and_teardown_test.rb +76 -0
  38. data/test/mocha_acceptance_test.rb +8 -8
  39. data/test/mocha_test_result_integration_test.rb +5 -6
  40. data/test/standalone_acceptance_test.rb +110 -0
  41. data/test/stubba_acceptance_test.rb +2 -2
  42. data/test/stubba_integration_test.rb +17 -24
  43. data/test/stubba_test_result_integration_test.rb +5 -6
  44. metadata +22 -18
  45. data/lib/shared/backtracefilter.rb +0 -46
  46. data/lib/smart_test_case.rb +0 -5
  47. data/lib/smart_test_case/multiple_setup_and_teardown.rb +0 -123
  48. data/lib/stubba/instance_method.rb +0 -18
  49. data/lib/stubba/setup_and_teardown.rb +0 -25
  50. data/test/smart_test_case/multiple_setup_and_teardown_test.rb +0 -192
  51. data/test/stubba/instance_method_test.rb +0 -46
  52. data/test/stubba/setup_and_teardown_test.rb +0 -134
@@ -1,46 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "test_helper")
2
- require 'method_definer'
3
-
4
- require 'stubba/instance_method'
5
-
6
- class InstanceMethodTest < Test::Unit::TestCase
7
-
8
- include Stubba
9
-
10
- def test_should_exist
11
- klass = Class.new { def method_x; end }
12
- instance = klass.new
13
- method = InstanceMethod.new(instance, :method_x)
14
-
15
- assert method.exists?
16
- end
17
-
18
- def test_should_not_exist
19
- klass = Class.new { }
20
- instance = klass.new
21
- method = InstanceMethod.new(instance, :non_existent_method)
22
-
23
- assert !method.exists?
24
- end
25
-
26
- def test_should_raise_assertion_failed_error_when_attempting_to_stub_non_existent_method
27
- klass = Class.new
28
- instance = klass.new
29
- method = InstanceMethod.new(instance, :non_existent_method)
30
-
31
- assert_raise(Test::Unit::AssertionFailedError) { method.stub }
32
- end
33
-
34
- def test_should_not_raise_assertion_failed_error_when_attempting_to_stub_existing_method
35
- klass = Class.new { def method_x; end }
36
- instance = klass.new
37
- method = InstanceMethod.new(instance, :method_x)
38
-
39
- assert_nothing_raised(Test::Unit::AssertionFailedError) { method.stub }
40
- end
41
-
42
- def test_should_inherit_from_class_method
43
- assert_equal ClassMethod, InstanceMethod.superclass
44
- end
45
-
46
- end
@@ -1,134 +0,0 @@
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_verify_all_expectations
45
- test_case = stubbed_test_case_class.new
46
- stubba = Mock.new
47
- stubba.expects(:verify_all)
48
- stubba.stubs(:unstub_all)
49
- $stubba = stubba
50
-
51
- test_case.teardown_stubs
52
-
53
- stubba.verify
54
- end
55
-
56
- def test_should_pass_block_to_add_assertion_to_test_case
57
- test_case = stubbed_test_case_class.new
58
- $stubba = Mock.new
59
- $stubba.stubs(:verify_all).yields
60
- $stubba.stubs(:unstub_all)
61
-
62
- test_case.teardown_stubs
63
-
64
- assert_equal true, test_case.add_assertion_called
65
- end
66
-
67
- def test_should_unstub_all_stubbed_methods
68
- test_case = stubbed_test_case_class.new
69
- stubba = Mock.new
70
- stubba.stubs(:verify_all)
71
- stubba.expects(:unstub_all)
72
- $stubba = stubba
73
-
74
- test_case.teardown_stubs
75
-
76
- stubba.verify
77
- end
78
-
79
- def test_should_unstub_all_stubbed_methods_even_if_verify_all_raises_exception
80
- test_case = stubbed_test_case_class.new
81
- stubba = Mock.new
82
- stubba.stubs(:verify_all).raises(Exception)
83
- stubba.expects(:unstub_all)
84
- $stubba = stubba
85
-
86
- assert_raises(Exception) { test_case.teardown_stubs }
87
-
88
- stubba.verify
89
- end
90
-
91
- def test_should_set_stubba_to_nil
92
- test_case = stubbed_test_case_class.new
93
- $stubba = Mock.new
94
- $stubba.stubs(:verify_all)
95
- $stubba.stubs(:unstub_all)
96
-
97
- test_case.teardown_stubs
98
-
99
- assert_nil $stubba
100
- end
101
-
102
- def test_should_set_stubba_to_nil_even_if_verify_all_raises_exception
103
- test_case = stubbed_test_case_class.new
104
- $stubba = Mock.new
105
- $stubba.stubs(:verify_all).raises(Exception)
106
- $stubba.stubs(:unstub_all)
107
-
108
- assert_raises(Exception) { test_case.teardown_stubs }
109
-
110
- assert_nil $stubba
111
- end
112
-
113
- def test_should_not_raise_exception_if_no_stubba_central_available
114
- test_case = stubbed_test_case_class.new
115
- $stubba = nil
116
- assert_nothing_raised { test_case.teardown_stubs }
117
- end
118
-
119
- private
120
-
121
- def stubbed_test_case_class
122
- Class.new do
123
- class << self
124
- define_method(:add_setup_method) {}
125
- define_method(:add_teardown_method) {}
126
- end
127
- attr_accessor :add_assertion_called
128
- define_method(:add_assertion) { self.add_assertion_called = true }
129
- include SetupAndTeardown
130
- end
131
- end
132
-
133
- end
134
-