mocha 0.5.6 → 3.1.0
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.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +92 -0
- data/.rubocop_todo.yml +39 -0
- data/.yardopts +25 -0
- data/CONTRIBUTING.md +7 -0
- data/COPYING.md +3 -0
- data/Gemfile +17 -0
- data/{MIT-LICENSE → MIT-LICENSE.md} +2 -2
- data/README.md +361 -0
- data/RELEASE.md +1247 -0
- data/Rakefile +165 -123
- data/gemfiles/Gemfile.minitest.latest +8 -0
- data/gemfiles/Gemfile.rubocop +9 -0
- data/gemfiles/Gemfile.test-unit.latest +8 -0
- data/lib/mocha/any_instance_method.rb +12 -26
- data/lib/mocha/any_instance_receiver.rb +20 -0
- data/lib/mocha/api.rb +213 -0
- data/lib/mocha/argument_iterator.rb +17 -0
- data/lib/mocha/backtrace_filter.rb +25 -0
- data/lib/mocha/block_matchers.rb +33 -0
- data/lib/mocha/cardinality.rb +110 -0
- data/lib/mocha/central.rb +33 -22
- data/lib/mocha/change_state_side_effect.rb +17 -0
- data/lib/mocha/class_methods.rb +67 -0
- data/lib/mocha/configuration.rb +338 -0
- data/lib/mocha/default_name.rb +15 -0
- data/lib/mocha/default_receiver.rb +13 -0
- data/lib/mocha/deprecation.rb +6 -15
- data/lib/mocha/detection/minitest.rb +25 -0
- data/lib/mocha/detection/test_unit.rb +30 -0
- data/lib/mocha/error_with_filtered_backtrace.rb +15 -0
- data/lib/mocha/exception_raiser.rb +11 -10
- data/lib/mocha/expectation.rb +562 -171
- data/lib/mocha/expectation_error.rb +9 -14
- data/lib/mocha/expectation_error_factory.rb +37 -0
- data/lib/mocha/expectation_list.rb +30 -14
- data/lib/mocha/hooks.rb +55 -0
- data/lib/mocha/ignoring_warning.rb +20 -0
- data/lib/mocha/impersonating_any_instance_name.rb +13 -0
- data/lib/mocha/impersonating_name.rb +13 -0
- data/lib/mocha/in_state_ordering_constraint.rb +17 -0
- data/lib/mocha/inspect.rb +54 -30
- data/lib/mocha/instance_method.rb +17 -4
- data/lib/mocha/integration/assertion_counter.rb +15 -0
- data/lib/mocha/integration/minitest/adapter.rb +71 -0
- data/lib/mocha/integration/minitest.rb +29 -0
- data/lib/mocha/integration/monkey_patcher.rb +26 -0
- data/lib/mocha/integration/test_unit/adapter.rb +61 -0
- data/lib/mocha/integration/test_unit.rb +29 -0
- data/lib/mocha/integration.rb +5 -0
- data/lib/mocha/invocation.rb +76 -0
- data/lib/mocha/logger.rb +26 -0
- data/lib/mocha/macos_version.rb +7 -0
- data/lib/mocha/method_matcher.rb +8 -10
- data/lib/mocha/minitest.rb +7 -0
- data/lib/mocha/mock.rb +333 -108
- data/lib/mocha/mockery.rb +192 -0
- data/lib/mocha/name.rb +13 -0
- data/lib/mocha/not_initialized_error.rb +9 -0
- data/lib/mocha/object_methods.rb +183 -0
- data/lib/mocha/object_receiver.rb +20 -0
- data/lib/mocha/parameter_matchers/all_of.rb +38 -28
- data/lib/mocha/parameter_matchers/any_of.rb +44 -33
- data/lib/mocha/parameter_matchers/any_parameters.rb +33 -26
- data/lib/mocha/parameter_matchers/anything.rb +31 -22
- data/lib/mocha/parameter_matchers/base_methods.rb +64 -0
- data/lib/mocha/parameter_matchers/equals.rb +36 -25
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +65 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +48 -29
- data/lib/mocha/parameter_matchers/has_entry.rb +90 -42
- data/lib/mocha/parameter_matchers/has_key.rb +39 -26
- data/lib/mocha/parameter_matchers/has_keys.rb +59 -0
- data/lib/mocha/parameter_matchers/has_value.rb +39 -26
- data/lib/mocha/parameter_matchers/includes.rb +88 -23
- data/lib/mocha/parameter_matchers/instance_methods.rb +28 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +37 -26
- data/lib/mocha/parameter_matchers/is_a.rb +38 -26
- data/lib/mocha/parameter_matchers/kind_of.rb +39 -26
- data/lib/mocha/parameter_matchers/not.rb +37 -26
- data/lib/mocha/parameter_matchers/optionally.rb +52 -17
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +91 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +37 -25
- data/lib/mocha/parameter_matchers/responds_with.rb +82 -0
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +55 -0
- data/lib/mocha/parameter_matchers.rb +12 -5
- data/lib/mocha/parameters_matcher.rb +28 -19
- data/lib/mocha/raised_exception.rb +13 -0
- data/lib/mocha/return_values.rb +13 -18
- data/lib/mocha/ruby_version.rb +7 -0
- data/lib/mocha/sequence.rb +23 -17
- data/lib/mocha/single_return_value.rb +8 -18
- data/lib/mocha/state_machine.rb +95 -0
- data/lib/mocha/stubbed_method.rb +96 -0
- data/lib/mocha/stubbing_error.rb +10 -0
- data/lib/mocha/test_unit.rb +7 -0
- data/lib/mocha/thrower.rb +15 -0
- data/lib/mocha/thrown_object.rb +14 -0
- data/lib/mocha/version.rb +5 -0
- data/lib/mocha/yield_parameters.rb +12 -20
- data/lib/mocha.rb +19 -17
- data/mocha.gemspec +40 -0
- metadata +129 -145
- data/COPYING +0 -3
- data/README +0 -35
- data/RELEASE +0 -188
- data/examples/misc.rb +0 -44
- data/examples/mocha.rb +0 -26
- data/examples/stubba.rb +0 -65
- data/lib/mocha/auto_verify.rb +0 -118
- data/lib/mocha/class_method.rb +0 -66
- data/lib/mocha/infinite_range.rb +0 -25
- data/lib/mocha/is_a.rb +0 -9
- data/lib/mocha/metaclass.rb +0 -7
- data/lib/mocha/missing_expectation.rb +0 -17
- data/lib/mocha/multiple_yields.rb +0 -20
- data/lib/mocha/no_yields.rb +0 -11
- data/lib/mocha/object.rb +0 -110
- data/lib/mocha/parameter_matchers/base.rb +0 -15
- data/lib/mocha/parameter_matchers/object.rb +0 -9
- data/lib/mocha/pretty_parameters.rb +0 -28
- data/lib/mocha/setup_and_teardown.rb +0 -23
- data/lib/mocha/single_yield.rb +0 -18
- data/lib/mocha/standalone.rb +0 -32
- data/lib/mocha/stub.rb +0 -18
- data/lib/mocha/test_case_adapter.rb +0 -49
- data/lib/mocha_standalone.rb +0 -2
- data/lib/stubba.rb +0 -2
- data/test/acceptance/expected_invocation_count_acceptance_test.rb +0 -187
- data/test/acceptance/mocha_acceptance_test.rb +0 -98
- data/test/acceptance/mock_with_initializer_block_acceptance_test.rb +0 -44
- data/test/acceptance/mocked_methods_dispatch_acceptance_test.rb +0 -71
- data/test/acceptance/optional_parameters_acceptance_test.rb +0 -63
- data/test/acceptance/parameter_matcher_acceptance_test.rb +0 -117
- data/test/acceptance/partial_mocks_acceptance_test.rb +0 -40
- data/test/acceptance/sequence_acceptance_test.rb +0 -179
- data/test/acceptance/standalone_acceptance_test.rb +0 -131
- data/test/acceptance/stubba_acceptance_test.rb +0 -102
- data/test/active_record_test_case.rb +0 -36
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -34
- data/test/integration/mocha_test_result_integration_test.rb +0 -105
- data/test/integration/stubba_integration_test.rb +0 -89
- data/test/integration/stubba_test_result_integration_test.rb +0 -85
- data/test/method_definer.rb +0 -18
- data/test/test_helper.rb +0 -12
- data/test/test_runner.rb +0 -31
- data/test/unit/any_instance_method_test.rb +0 -126
- data/test/unit/array_inspect_test.rb +0 -16
- data/test/unit/auto_verify_test.rb +0 -129
- data/test/unit/central_test.rb +0 -124
- data/test/unit/class_method_test.rb +0 -200
- data/test/unit/date_time_inspect_test.rb +0 -21
- data/test/unit/expectation_error_test.rb +0 -24
- data/test/unit/expectation_list_test.rb +0 -75
- data/test/unit/expectation_raiser_test.rb +0 -28
- data/test/unit/expectation_test.rb +0 -483
- data/test/unit/hash_inspect_test.rb +0 -16
- data/test/unit/infinite_range_test.rb +0 -53
- data/test/unit/metaclass_test.rb +0 -22
- data/test/unit/method_matcher_test.rb +0 -23
- data/test/unit/missing_expectation_test.rb +0 -42
- data/test/unit/mock_test.rb +0 -323
- data/test/unit/multiple_yields_test.rb +0 -18
- data/test/unit/no_yield_test.rb +0 -18
- data/test/unit/object_inspect_test.rb +0 -37
- data/test/unit/object_test.rb +0 -165
- data/test/unit/parameter_matchers/all_of_test.rb +0 -26
- data/test/unit/parameter_matchers/any_of_test.rb +0 -26
- data/test/unit/parameter_matchers/anything_test.rb +0 -21
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -30
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -40
- data/test/unit/parameter_matchers/has_key_test.rb +0 -25
- data/test/unit/parameter_matchers/has_value_test.rb +0 -25
- data/test/unit/parameter_matchers/includes_test.rb +0 -25
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -25
- data/test/unit/parameter_matchers/is_a_test.rb +0 -25
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -25
- data/test/unit/parameter_matchers/not_test.rb +0 -26
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -25
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
- data/test/unit/parameters_matcher_test.rb +0 -121
- data/test/unit/return_values_test.rb +0 -63
- data/test/unit/sequence_test.rb +0 -104
- data/test/unit/setup_and_teardown_test.rb +0 -76
- data/test/unit/single_return_value_test.rb +0 -33
- data/test/unit/single_yield_test.rb +0 -18
- data/test/unit/string_inspect_test.rb +0 -11
- data/test/unit/stub_test.rb +0 -24
- data/test/unit/yield_parameters_test.rb +0 -93
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha/auto_verify'
|
|
3
|
-
require 'method_definer'
|
|
4
|
-
|
|
5
|
-
class AutoVerifyTest < Test::Unit::TestCase
|
|
6
|
-
|
|
7
|
-
attr_reader :test_case
|
|
8
|
-
|
|
9
|
-
def setup
|
|
10
|
-
@test_case = Object.new
|
|
11
|
-
class << test_case
|
|
12
|
-
include Mocha::AutoVerify
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_should_build_mock
|
|
17
|
-
mock = test_case.mock
|
|
18
|
-
assert mock.is_a?(Mocha::Mock)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_should_add_expectations_to_mock
|
|
22
|
-
mock = test_case.mock(:method_1 => 'result_1', :method_2 => 'result_2')
|
|
23
|
-
assert_equal 'result_1', mock.method_1
|
|
24
|
-
assert_equal 'result_2', mock.method_2
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_should_build_stub
|
|
28
|
-
stub = test_case.stub
|
|
29
|
-
assert stub.is_a?(Mocha::Mock)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_should_add_expectation_to_stub
|
|
33
|
-
stub = test_case.stub(:method_1 => 'result_1', :method_2 => 'result_2')
|
|
34
|
-
assert_equal 'result_1', stub.method_1
|
|
35
|
-
assert_equal 'result_2', stub.method_2
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_should_build_stub_that_stubs_all_methods
|
|
39
|
-
stub = test_case.stub_everything
|
|
40
|
-
assert stub.everything_stubbed
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def test_should_add_expectations_to_stub_that_stubs_all_methods
|
|
44
|
-
stub = test_case.stub_everything(:method_1 => 'result_1', :method_2 => 'result_2')
|
|
45
|
-
assert_equal 'result_1', stub.method_1
|
|
46
|
-
assert_equal 'result_2', stub.method_2
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_should_always_new_mock
|
|
50
|
-
assert_not_equal test_case.mock, test_case.mock
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_should_always_build_new_stub
|
|
54
|
-
assert_not_equal test_case.stub, test_case.stub
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_should_always_build_new_stub_that_stubs_all_methods
|
|
58
|
-
assert_not_equal test_case.stub, test_case.stub
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_should_store_each_new_mock
|
|
62
|
-
expected = Array.new(3) { test_case.mock }
|
|
63
|
-
assert_equal expected, test_case.mocks
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_should_store_each_new_stub
|
|
67
|
-
expected = Array.new(3) { test_case.stub }
|
|
68
|
-
assert_equal expected, test_case.mocks
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def test_should_store_each_new_stub_that_stubs_all_methods
|
|
72
|
-
expected = Array.new(3) { test_case.stub_everything }
|
|
73
|
-
assert_equal expected, test_case.mocks
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_should_verify_each_mock
|
|
77
|
-
mocks = Array.new(3) do
|
|
78
|
-
mock = Object.new
|
|
79
|
-
mock.define_instance_accessor(:verify_called)
|
|
80
|
-
class << mock
|
|
81
|
-
def verify(&block)
|
|
82
|
-
self.verify_called = true
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
mock
|
|
86
|
-
end
|
|
87
|
-
test_case.replace_instance_method(:mocks) { mocks }
|
|
88
|
-
test_case.verify_mocks
|
|
89
|
-
assert mocks.all? { |mock| mock.verify_called }
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def test_should_yield_to_block_for_each_assertion
|
|
93
|
-
mock_class = Class.new do
|
|
94
|
-
def verify(&block); yield; end
|
|
95
|
-
end
|
|
96
|
-
mock = mock_class.new
|
|
97
|
-
test_case.replace_instance_method(:mocks) { [mock] }
|
|
98
|
-
yielded = false
|
|
99
|
-
test_case.verify_mocks { yielded = true }
|
|
100
|
-
assert yielded
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def test_should_reset_mocks_on_teardown
|
|
104
|
-
mock = Class.new { define_method(:verify) {} }.new
|
|
105
|
-
test_case.mocks << mock
|
|
106
|
-
test_case.teardown_mocks
|
|
107
|
-
assert test_case.mocks.empty?
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def test_should_create_named_mock
|
|
111
|
-
mock = test_case.mock('named_mock')
|
|
112
|
-
assert_equal '#<Mock:named_mock>', mock.mocha_inspect
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_should_create_named_stub
|
|
116
|
-
stub = test_case.stub('named_stub')
|
|
117
|
-
assert_equal '#<Mock:named_stub>', stub.mocha_inspect
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def test_should_create_named_stub_that_stubs_all_methods
|
|
121
|
-
stub = test_case.stub_everything('named_stub')
|
|
122
|
-
assert_equal '#<Mock:named_stub>', stub.mocha_inspect
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def test_should_build_sequence
|
|
126
|
-
assert_not_nil test_case.sequence('name')
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
end
|
data/test/unit/central_test.rb
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
|
|
3
|
-
require 'mocha/central'
|
|
4
|
-
require 'mocha/mock'
|
|
5
|
-
require 'method_definer'
|
|
6
|
-
|
|
7
|
-
class CentralTest < Test::Unit::TestCase
|
|
8
|
-
|
|
9
|
-
include Mocha
|
|
10
|
-
|
|
11
|
-
def test_should_start_with_empty_stubba_methods
|
|
12
|
-
stubba = Central.new
|
|
13
|
-
|
|
14
|
-
assert_equal [], stubba.stubba_methods
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_should_stub_method_if_not_already_stubbed
|
|
18
|
-
method = Mock.new
|
|
19
|
-
method.expects(:stub)
|
|
20
|
-
stubba = Central.new
|
|
21
|
-
|
|
22
|
-
stubba.stub(method)
|
|
23
|
-
|
|
24
|
-
method.verify
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_should_not_stub_method_if_already_stubbed
|
|
28
|
-
method = Mock.new
|
|
29
|
-
method.expects(:stub).times(0)
|
|
30
|
-
stubba = Central.new
|
|
31
|
-
stubba_methods = Mock.new
|
|
32
|
-
stubba_methods.stubs(:include?).with(method).returns(true)
|
|
33
|
-
stubba.stubba_methods = stubba_methods
|
|
34
|
-
|
|
35
|
-
stubba.stub(method)
|
|
36
|
-
|
|
37
|
-
method.verify
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_should_record_method
|
|
41
|
-
method = Mock.new
|
|
42
|
-
method.expects(:stub)
|
|
43
|
-
stubba = Central.new
|
|
44
|
-
|
|
45
|
-
stubba.stub(method)
|
|
46
|
-
|
|
47
|
-
assert_equal [method], stubba.stubba_methods
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_should_unstub_all_methods
|
|
51
|
-
stubba = Central.new
|
|
52
|
-
method_1 = Mock.new
|
|
53
|
-
method_1.expects(:unstub)
|
|
54
|
-
method_2 = Mock.new
|
|
55
|
-
method_2.expects(:unstub)
|
|
56
|
-
stubba.stubba_methods = [method_1, method_2]
|
|
57
|
-
|
|
58
|
-
stubba.unstub_all
|
|
59
|
-
|
|
60
|
-
assert_equal [], stubba.stubba_methods
|
|
61
|
-
method_1.verify
|
|
62
|
-
method_2.verify
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_should_collect_mocks_from_all_methods
|
|
66
|
-
method_1 = Mock.new
|
|
67
|
-
method_1.stubs(:mock).returns(:mock_1)
|
|
68
|
-
|
|
69
|
-
method_2 = Mock.new
|
|
70
|
-
method_2.stubs(:mock).returns(:mock_2)
|
|
71
|
-
|
|
72
|
-
stubba = Central.new
|
|
73
|
-
stubba.stubba_methods = [method_1, method_2]
|
|
74
|
-
|
|
75
|
-
assert_equal 2, stubba.unique_mocks.length
|
|
76
|
-
assert stubba.unique_mocks.include?(:mock_1)
|
|
77
|
-
assert stubba.unique_mocks.include?(:mock_2)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_should_return_unique_mochas
|
|
81
|
-
method_1 = Mock.new
|
|
82
|
-
method_1.stubs(:mock).returns(:mock_1)
|
|
83
|
-
|
|
84
|
-
method_2 = Mock.new
|
|
85
|
-
method_2.stubs(:mock).returns(:mock_1)
|
|
86
|
-
|
|
87
|
-
stubba = Central.new
|
|
88
|
-
stubba.stubba_methods = [method_1, method_2]
|
|
89
|
-
|
|
90
|
-
assert_equal [:mock_1], stubba.unique_mocks
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def test_should_call_verify_on_all_unique_mocks
|
|
94
|
-
mock_class = Class.new do
|
|
95
|
-
attr_accessor :verify_called
|
|
96
|
-
def verify
|
|
97
|
-
self.verify_called = true
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
mocks = [mock_class.new, mock_class.new]
|
|
101
|
-
stubba = Central.new
|
|
102
|
-
stubba.replace_instance_method(:unique_mocks) { mocks }
|
|
103
|
-
|
|
104
|
-
stubba.verify_all
|
|
105
|
-
|
|
106
|
-
assert mocks.all? { |mock| mock.verify_called }
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def test_should_call_verify_on_all_unique_mochas
|
|
110
|
-
mock_class = Class.new do
|
|
111
|
-
def verify(&block)
|
|
112
|
-
yield if block_given?
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
stubba = Central.new
|
|
116
|
-
stubba.replace_instance_method(:unique_mocks) { [mock_class.new] }
|
|
117
|
-
yielded = false
|
|
118
|
-
|
|
119
|
-
stubba.verify_all { yielded = true }
|
|
120
|
-
|
|
121
|
-
assert yielded
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
end
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'method_definer'
|
|
3
|
-
require 'mocha/mock'
|
|
4
|
-
|
|
5
|
-
require 'mocha/class_method'
|
|
6
|
-
|
|
7
|
-
class ClassMethodTest < Test::Unit::TestCase
|
|
8
|
-
|
|
9
|
-
include Mocha
|
|
10
|
-
|
|
11
|
-
def test_should_provide_hidden_version_of_method_name_starting_with_prefix
|
|
12
|
-
method = ClassMethod.new(nil, :original_method_name)
|
|
13
|
-
assert_match(/^__stubba__/, method.hidden_method)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_should_provide_hidden_version_of_method_name_ending_with_suffix
|
|
17
|
-
method = ClassMethod.new(nil, :original_method_name)
|
|
18
|
-
assert_match(/__stubba__$/, method.hidden_method)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_should_provide_hidden_version_of_method_name_including_original_method_name
|
|
22
|
-
method = ClassMethod.new(nil, :original_method_name)
|
|
23
|
-
assert_match(/original_method_name/, method.hidden_method)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def test_should_provide_hidden_version_of_method_name_substituting_question_mark
|
|
27
|
-
method = ClassMethod.new(nil, :question_mark?)
|
|
28
|
-
assert_no_match(/\?/, method.hidden_method)
|
|
29
|
-
assert_match(/question_mark_substituted_character_63/, method.hidden_method)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_should_provide_hidden_version_of_method_name_substituting_exclamation_mark
|
|
33
|
-
method = ClassMethod.new(nil, :exclamation_mark!)
|
|
34
|
-
assert_no_match(/!/, method.hidden_method)
|
|
35
|
-
assert_match(/exclamation_mark_substituted_character_33/, method.hidden_method)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_should_provide_hidden_version_of_method_name_substituting_equals_sign
|
|
39
|
-
method = ClassMethod.new(nil, :equals_sign=)
|
|
40
|
-
assert_no_match(/\=/, method.hidden_method)
|
|
41
|
-
assert_match(/equals_sign_substituted_character_61/, method.hidden_method)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_should_provide_hidden_version_of_method_name_substituting_brackets
|
|
45
|
-
method = ClassMethod.new(nil, :[])
|
|
46
|
-
assert_no_match(/\[\]/, method.hidden_method)
|
|
47
|
-
assert_match(/substituted_character_91__substituted_character_93/, method.hidden_method)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_should_provide_hidden_version_of_method_name_substituting_plus_sign
|
|
51
|
-
method = ClassMethod.new(nil, :+)
|
|
52
|
-
assert_no_match(/\+/, method.hidden_method)
|
|
53
|
-
assert_match(/substituted_character_43/, method.hidden_method)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_should_hide_original_method
|
|
57
|
-
klass = Class.new { def self.method_x; end }
|
|
58
|
-
method = ClassMethod.new(klass, :method_x)
|
|
59
|
-
hidden_method_x = method.hidden_method
|
|
60
|
-
|
|
61
|
-
method.hide_original_method
|
|
62
|
-
|
|
63
|
-
assert klass.respond_to?(hidden_method_x)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_should_respond_to_original_method_name_after_original_method_has_been_hidden
|
|
67
|
-
klass = Class.new { def self.original_method_name; end }
|
|
68
|
-
method = ClassMethod.new(klass, :original_method_name)
|
|
69
|
-
hidden_method_x = method.hidden_method
|
|
70
|
-
|
|
71
|
-
method.hide_original_method
|
|
72
|
-
|
|
73
|
-
assert klass.respond_to?(:original_method_name)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_should_not_hide_original_method_if_method_not_defined
|
|
77
|
-
klass = Class.new
|
|
78
|
-
method = ClassMethod.new(klass, :method_x)
|
|
79
|
-
hidden_method_x = method.hidden_method
|
|
80
|
-
|
|
81
|
-
method.hide_original_method
|
|
82
|
-
|
|
83
|
-
assert_equal false, klass.respond_to?(hidden_method_x)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def test_should_define_a_new_method_which_should_call_mocha_method_missing
|
|
87
|
-
klass = Class.new { def self.method_x; end }
|
|
88
|
-
mocha = Mocha::Mock.new
|
|
89
|
-
klass.define_instance_method(:mocha) { mocha }
|
|
90
|
-
mocha.expects(:method_x).with(:param1, :param2).returns(:result)
|
|
91
|
-
method = ClassMethod.new(klass, :method_x)
|
|
92
|
-
|
|
93
|
-
method.hide_original_method
|
|
94
|
-
method.define_new_method
|
|
95
|
-
result = klass.method_x(:param1, :param2)
|
|
96
|
-
|
|
97
|
-
assert_equal :result, result
|
|
98
|
-
mocha.verify
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def test_should_remove_new_method
|
|
102
|
-
klass = Class.new { def self.method_x; end }
|
|
103
|
-
method = ClassMethod.new(klass, :method_x)
|
|
104
|
-
|
|
105
|
-
method.remove_new_method
|
|
106
|
-
|
|
107
|
-
assert_equal false, klass.respond_to?(:method_x)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def test_should_restore_original_method
|
|
111
|
-
klass = Class.new { def self.method_x; end }
|
|
112
|
-
method = ClassMethod.new(klass, :method_x)
|
|
113
|
-
hidden_method_x = method.hidden_method.to_sym
|
|
114
|
-
klass.define_instance_method(hidden_method_x) { :original_result }
|
|
115
|
-
|
|
116
|
-
method.remove_new_method
|
|
117
|
-
method.restore_original_method
|
|
118
|
-
|
|
119
|
-
assert_equal :original_result, klass.method_x
|
|
120
|
-
assert_equal false, klass.respond_to?(hidden_method_x)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def test_should_not_restore_original_method_if_hidden_method_is_not_defined
|
|
124
|
-
klass = Class.new { def self.method_x; :new_result; end }
|
|
125
|
-
method = ClassMethod.new(klass, :method_x)
|
|
126
|
-
|
|
127
|
-
method.restore_original_method
|
|
128
|
-
|
|
129
|
-
assert_equal :new_result, klass.method_x
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def test_should_call_hide_original_method
|
|
133
|
-
klass = Class.new { def self.method_x; end }
|
|
134
|
-
method = ClassMethod.new(klass, :method_x)
|
|
135
|
-
method.hide_original_method
|
|
136
|
-
method.define_instance_accessor(:hide_called)
|
|
137
|
-
method.replace_instance_method(:hide_original_method) { self.hide_called = true }
|
|
138
|
-
|
|
139
|
-
method.stub
|
|
140
|
-
|
|
141
|
-
assert method.hide_called
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def test_should_call_define_new_method
|
|
145
|
-
klass = Class.new { def self.method_x; end }
|
|
146
|
-
method = ClassMethod.new(klass, :method_x)
|
|
147
|
-
method.define_instance_accessor(:define_called)
|
|
148
|
-
method.replace_instance_method(:define_new_method) { self.define_called = true }
|
|
149
|
-
|
|
150
|
-
method.stub
|
|
151
|
-
|
|
152
|
-
assert method.define_called
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def test_should_call_remove_new_method
|
|
156
|
-
klass = Class.new { def self.method_x; end }
|
|
157
|
-
klass.define_instance_method(:reset_mocha) { }
|
|
158
|
-
method = ClassMethod.new(klass, :method_x)
|
|
159
|
-
method.define_instance_accessor(:remove_called)
|
|
160
|
-
method.replace_instance_method(:remove_new_method) { self.remove_called = true }
|
|
161
|
-
|
|
162
|
-
method.unstub
|
|
163
|
-
|
|
164
|
-
assert method.remove_called
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def test_should_call_restore_original_method
|
|
168
|
-
klass = Class.new { def self.method_x; end }
|
|
169
|
-
klass.define_instance_method(:reset_mocha) { }
|
|
170
|
-
method = ClassMethod.new(klass, :method_x)
|
|
171
|
-
method.define_instance_accessor(:restore_called)
|
|
172
|
-
method.replace_instance_method(:restore_original_method) { self.restore_called = true }
|
|
173
|
-
|
|
174
|
-
method.unstub
|
|
175
|
-
|
|
176
|
-
assert method.restore_called
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def test_should_call_reset_mocha
|
|
180
|
-
klass = Class.new { def self.method_x; end }
|
|
181
|
-
klass.define_instance_accessor(:reset_called)
|
|
182
|
-
klass.define_instance_method(:reset_mocha) { self.reset_called = true }
|
|
183
|
-
method = ClassMethod.new(klass, :method_x)
|
|
184
|
-
method.replace_instance_method(:restore_original_method) { }
|
|
185
|
-
|
|
186
|
-
method.unstub
|
|
187
|
-
|
|
188
|
-
assert klass.reset_called
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def test_should_return_mock_for_stubbee
|
|
192
|
-
mocha = Object.new
|
|
193
|
-
stubbee = Object.new
|
|
194
|
-
stubbee.define_instance_accessor(:mocha) { mocha }
|
|
195
|
-
stubbee.mocha = nil
|
|
196
|
-
method = ClassMethod.new(stubbee, :method_name)
|
|
197
|
-
assert_equal stubbee.mocha, method.mock
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha/inspect'
|
|
3
|
-
|
|
4
|
-
class TimeDateInspectTest < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
def test_should_use_include_date_in_seconds
|
|
7
|
-
time = Time.now
|
|
8
|
-
assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_should_use_to_s_for_date
|
|
12
|
-
date = Date.new(2006, 1, 1)
|
|
13
|
-
assert_equal date.to_s, date.mocha_inspect
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_should_use_to_s_for_datetime
|
|
17
|
-
datetime = DateTime.new(2006, 1, 1)
|
|
18
|
-
assert_equal datetime.to_s, datetime.mocha_inspect
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha/expectation_error'
|
|
3
|
-
|
|
4
|
-
class ExpectationErrorTest < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
include Mocha
|
|
7
|
-
|
|
8
|
-
def test_should_exclude_mocha_locations_from_backtrace
|
|
9
|
-
mocha_lib = "/username/workspace/mocha_wibble/lib/"
|
|
10
|
-
backtrace = [ mocha_lib + 'exclude/me/1', mocha_lib + 'exclude/me/2', '/keep/me', mocha_lib + 'exclude/me/3']
|
|
11
|
-
expectation_error = ExpectationError.new(nil, backtrace, mocha_lib)
|
|
12
|
-
assert_equal ['/keep/me'], expectation_error.backtrace
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def test_should_determine_path_for_mocha_lib_directory
|
|
16
|
-
assert_match Regexp.new("/lib/$"), ExpectationError::LIB_DIRECTORY
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_should_set_error_message
|
|
20
|
-
expectation_error = ExpectationError.new('message')
|
|
21
|
-
assert_equal 'message', expectation_error.message
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
end
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha/expectation_list'
|
|
3
|
-
require 'mocha/expectation'
|
|
4
|
-
require 'set'
|
|
5
|
-
require 'method_definer'
|
|
6
|
-
|
|
7
|
-
class ExpectationListTest < Test::Unit::TestCase
|
|
8
|
-
|
|
9
|
-
include Mocha
|
|
10
|
-
|
|
11
|
-
def test_should_return_added_expectation
|
|
12
|
-
expectation_list = ExpectationList.new
|
|
13
|
-
expectation = Expectation.new(nil, :my_method)
|
|
14
|
-
assert_same expectation, expectation_list.add(expectation)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_should_find_matching_expectation
|
|
18
|
-
expectation_list = ExpectationList.new
|
|
19
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
|
20
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
|
21
|
-
expectation_list.add(expectation1)
|
|
22
|
-
expectation_list.add(expectation2)
|
|
23
|
-
assert_same expectation2, expectation_list.detect(:my_method, :argument3, :argument4)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def test_should_find_most_recent_matching_expectation
|
|
27
|
-
expectation_list = ExpectationList.new
|
|
28
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
|
29
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
|
30
|
-
expectation_list.add(expectation1)
|
|
31
|
-
expectation_list.add(expectation2)
|
|
32
|
-
assert_same expectation2, expectation_list.detect(:my_method, :argument1, :argument2)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_should_find_most_recent_matching_expectation_but_give_preference_to_those_allowing_invocations
|
|
36
|
-
expectation_list = ExpectationList.new
|
|
37
|
-
expectation1 = Expectation.new(nil, :my_method)
|
|
38
|
-
expectation2 = Expectation.new(nil, :my_method)
|
|
39
|
-
expectation1.define_instance_method(:invocations_allowed?) { true }
|
|
40
|
-
expectation2.define_instance_method(:invocations_allowed?) { false }
|
|
41
|
-
expectation_list.add(expectation1)
|
|
42
|
-
expectation_list.add(expectation2)
|
|
43
|
-
assert_same expectation1, expectation_list.detect(:my_method)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def test_should_find_most_recent_matching_expectation_if_no_matching_expectations_allow_invocations
|
|
47
|
-
expectation_list = ExpectationList.new
|
|
48
|
-
expectation1 = Expectation.new(nil, :my_method)
|
|
49
|
-
expectation2 = Expectation.new(nil, :my_method)
|
|
50
|
-
expectation1.define_instance_method(:invocations_allowed?) { false }
|
|
51
|
-
expectation2.define_instance_method(:invocations_allowed?) { false }
|
|
52
|
-
expectation_list.add(expectation1)
|
|
53
|
-
expectation_list.add(expectation2)
|
|
54
|
-
assert_same expectation2, expectation_list.detect(:my_method)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_should_find_expectations_for_the_same_method_no_matter_what_the_arguments
|
|
58
|
-
expectation_list = ExpectationList.new
|
|
59
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
|
60
|
-
expectation_list.add(expectation1)
|
|
61
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
|
62
|
-
expectation_list.add(expectation2)
|
|
63
|
-
assert_equal [expectation1, expectation2].to_set, expectation_list.similar(:my_method).to_set
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_should_ignore_expectations_for_different_methods
|
|
67
|
-
expectation_list = ExpectationList.new
|
|
68
|
-
expectation1 = Expectation.new(nil, :method1).with(:argument1, :argument2)
|
|
69
|
-
expectation_list.add(expectation1)
|
|
70
|
-
expectation2 = Expectation.new(nil, :method2).with(:argument1, :argument2)
|
|
71
|
-
expectation_list.add(expectation2)
|
|
72
|
-
assert_equal [expectation2], expectation_list.similar(:method2)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
|
|
3
|
-
require 'mocha/exception_raiser'
|
|
4
|
-
|
|
5
|
-
class ExceptionRaiserTest < Test::Unit::TestCase
|
|
6
|
-
|
|
7
|
-
include Mocha
|
|
8
|
-
|
|
9
|
-
def test_should_raise_exception_with_specified_class_and_default_message
|
|
10
|
-
exception_class = Class.new(StandardError)
|
|
11
|
-
raiser = ExceptionRaiser.new(exception_class, nil)
|
|
12
|
-
exception = assert_raises(exception_class) { raiser.evaluate }
|
|
13
|
-
assert_equal exception_class.to_s, exception.message
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_should_raise_exception_with_specified_class_and_message
|
|
17
|
-
exception_class = Class.new(StandardError)
|
|
18
|
-
raiser = ExceptionRaiser.new(exception_class, 'message')
|
|
19
|
-
exception = assert_raises(exception_class) { raiser.evaluate }
|
|
20
|
-
assert_equal 'message', exception.message
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
|
24
|
-
raiser = ExceptionRaiser.new(Interrupt, nil)
|
|
25
|
-
assert_raises(Interrupt) { raiser.evaluate }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|