mocha 0.5.6 → 3.0.2
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 +1235 -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 +15 -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 +19 -14
- 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 +553 -168
- 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 +56 -22
- 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 +13 -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 +199 -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/mise.toml +2 -0
- data/mocha.gemspec +40 -0
- metadata +130 -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,71 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha'
|
|
3
|
-
require 'test_runner'
|
|
4
|
-
|
|
5
|
-
class MockedMethodDispatchAcceptanceTest < Test::Unit::TestCase
|
|
6
|
-
|
|
7
|
-
include TestRunner
|
|
8
|
-
|
|
9
|
-
def test_should_find_latest_matching_expectation
|
|
10
|
-
test_result = run_test do
|
|
11
|
-
mock = mock()
|
|
12
|
-
mock.stubs(:method).returns(1)
|
|
13
|
-
mock.stubs(:method).returns(2)
|
|
14
|
-
assert_equal 2, mock.method
|
|
15
|
-
assert_equal 2, mock.method
|
|
16
|
-
assert_equal 2, mock.method
|
|
17
|
-
end
|
|
18
|
-
assert_passed(test_result)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_should_find_latest_expectation_which_has_not_stopped_matching
|
|
22
|
-
test_result = run_test do
|
|
23
|
-
mock = mock()
|
|
24
|
-
mock.stubs(:method).returns(1)
|
|
25
|
-
mock.stubs(:method).once.returns(2)
|
|
26
|
-
assert_equal 2, mock.method
|
|
27
|
-
assert_equal 1, mock.method
|
|
28
|
-
assert_equal 1, mock.method
|
|
29
|
-
end
|
|
30
|
-
assert_passed(test_result)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_should_keep_finding_later_stub_and_so_never_satisfy_earlier_expectation
|
|
34
|
-
test_result = run_test do
|
|
35
|
-
mock = mock()
|
|
36
|
-
mock.expects(:method).returns(1)
|
|
37
|
-
mock.stubs(:method).returns(2)
|
|
38
|
-
assert_equal 2, mock.method
|
|
39
|
-
assert_equal 2, mock.method
|
|
40
|
-
assert_equal 2, mock.method
|
|
41
|
-
end
|
|
42
|
-
assert_failed(test_result)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_should_find_later_expectation_until_it_stops_matching_then_find_earlier_stub
|
|
46
|
-
test_result = run_test do
|
|
47
|
-
mock = mock()
|
|
48
|
-
mock.stubs(:method).returns(1)
|
|
49
|
-
mock.expects(:method).returns(2)
|
|
50
|
-
assert_equal 2, mock.method
|
|
51
|
-
assert_equal 1, mock.method
|
|
52
|
-
assert_equal 1, mock.method
|
|
53
|
-
end
|
|
54
|
-
assert_passed(test_result)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_should_find_latest_expectation_with_range_of_expected_invocation_count_which_has_not_stopped_matching
|
|
58
|
-
test_result = run_test do
|
|
59
|
-
mock = mock()
|
|
60
|
-
mock.stubs(:method).returns(1)
|
|
61
|
-
mock.stubs(:method).times(2..3).returns(2)
|
|
62
|
-
assert_equal 2, mock.method
|
|
63
|
-
assert_equal 2, mock.method
|
|
64
|
-
assert_equal 2, mock.method
|
|
65
|
-
assert_equal 1, mock.method
|
|
66
|
-
assert_equal 1, mock.method
|
|
67
|
-
end
|
|
68
|
-
assert_passed(test_result)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha'
|
|
3
|
-
require 'test_runner'
|
|
4
|
-
|
|
5
|
-
class OptionalParameterMatcherAcceptanceTest < Test::Unit::TestCase
|
|
6
|
-
|
|
7
|
-
include TestRunner
|
|
8
|
-
|
|
9
|
-
def test_should_pass_if_all_required_parameters_match_and_no_optional_parameters_are_supplied
|
|
10
|
-
test_result = run_test do
|
|
11
|
-
mock = mock()
|
|
12
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
|
13
|
-
mock.method(1, 2)
|
|
14
|
-
end
|
|
15
|
-
assert_passed(test_result)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_should_pass_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied
|
|
19
|
-
test_result = run_test do
|
|
20
|
-
mock = mock()
|
|
21
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
|
22
|
-
mock.method(1, 2, 3)
|
|
23
|
-
end
|
|
24
|
-
assert_passed(test_result)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_should_pass_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied
|
|
28
|
-
test_result = run_test do
|
|
29
|
-
mock = mock()
|
|
30
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
|
31
|
-
mock.method(1, 2, 3, 4)
|
|
32
|
-
end
|
|
33
|
-
assert_passed(test_result)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_should_fail_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied
|
|
37
|
-
test_result = run_test do
|
|
38
|
-
mock = mock()
|
|
39
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
|
40
|
-
mock.method(1, 2, 3, 4, 5)
|
|
41
|
-
end
|
|
42
|
-
assert_failed(test_result)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_should_fail_if_all_required_parameters_match_but_some_optional_parameters_do_not_match
|
|
46
|
-
test_result = run_test do
|
|
47
|
-
mock = mock()
|
|
48
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
|
49
|
-
mock.method(1, 2, 4)
|
|
50
|
-
end
|
|
51
|
-
assert_failed(test_result)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_should_fail_if_all_required_parameters_match_but_no_optional_parameters_match
|
|
55
|
-
test_result = run_test do
|
|
56
|
-
mock = mock()
|
|
57
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
|
58
|
-
mock.method(1, 2, 4, 5)
|
|
59
|
-
end
|
|
60
|
-
assert_failed(test_result)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
end
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha'
|
|
3
|
-
require 'test_runner'
|
|
4
|
-
|
|
5
|
-
class ParameterMatcherAcceptanceTest < Test::Unit::TestCase
|
|
6
|
-
|
|
7
|
-
include TestRunner
|
|
8
|
-
|
|
9
|
-
def test_should_match_hash_parameter_with_specified_key
|
|
10
|
-
test_result = run_test do
|
|
11
|
-
mock = mock()
|
|
12
|
-
mock.expects(:method).with(has_key(:key_1))
|
|
13
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
|
14
|
-
end
|
|
15
|
-
assert_passed(test_result)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_should_not_match_hash_parameter_with_specified_key
|
|
19
|
-
test_result = run_test do
|
|
20
|
-
mock = mock()
|
|
21
|
-
mock.expects(:method).with(has_key(:key_1))
|
|
22
|
-
mock.method(:key_2 => 'value_2')
|
|
23
|
-
end
|
|
24
|
-
assert_failed(test_result)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_should_match_hash_parameter_with_specified_value
|
|
28
|
-
test_result = run_test do
|
|
29
|
-
mock = mock()
|
|
30
|
-
mock.expects(:method).with(has_value('value_1'))
|
|
31
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
|
32
|
-
end
|
|
33
|
-
assert_passed(test_result)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_should_not_match_hash_parameter_with_specified_value
|
|
37
|
-
test_result = run_test do
|
|
38
|
-
mock = mock()
|
|
39
|
-
mock.expects(:method).with(has_value('value_1'))
|
|
40
|
-
mock.method(:key_2 => 'value_2')
|
|
41
|
-
end
|
|
42
|
-
assert_failed(test_result)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_should_match_hash_parameter_with_specified_key_value_pair
|
|
46
|
-
test_result = run_test do
|
|
47
|
-
mock = mock()
|
|
48
|
-
mock.expects(:method).with(has_entry(:key_1, 'value_1'))
|
|
49
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
|
50
|
-
end
|
|
51
|
-
assert_passed(test_result)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_should_not_match_hash_parameter_with_specified_key_value_pair
|
|
55
|
-
test_result = run_test do
|
|
56
|
-
mock = mock()
|
|
57
|
-
mock.expects(:method).with(has_entry(:key_1, 'value_2'))
|
|
58
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
|
59
|
-
end
|
|
60
|
-
assert_failed(test_result)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def test_should_match_hash_parameter_with_specified_hash_entry
|
|
64
|
-
test_result = run_test do
|
|
65
|
-
mock = mock()
|
|
66
|
-
mock.expects(:method).with(has_entry(:key_1 => 'value_1'))
|
|
67
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
|
68
|
-
end
|
|
69
|
-
assert_passed(test_result)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def test_should_not_match_hash_parameter_with_specified_hash_entry
|
|
73
|
-
test_result = run_test do
|
|
74
|
-
mock = mock()
|
|
75
|
-
mock.expects(:method).with(has_entry(:key_1 => 'value_2'))
|
|
76
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
|
77
|
-
end
|
|
78
|
-
assert_failed(test_result)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def test_should_match_hash_parameter_with_specified_entries
|
|
82
|
-
test_result = run_test do
|
|
83
|
-
mock = mock()
|
|
84
|
-
mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2'))
|
|
85
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3')
|
|
86
|
-
end
|
|
87
|
-
assert_passed(test_result)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def test_should_not_match_hash_parameter_with_specified_entries
|
|
91
|
-
test_result = run_test do
|
|
92
|
-
mock = mock()
|
|
93
|
-
mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2'))
|
|
94
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_3')
|
|
95
|
-
end
|
|
96
|
-
assert_failed(test_result)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def test_should_match_parameter_that_matches_regular_expression
|
|
100
|
-
test_result = run_test do
|
|
101
|
-
mock = mock()
|
|
102
|
-
mock.expects(:method).with(regexp_matches(/meter/))
|
|
103
|
-
mock.method('this parameter should match')
|
|
104
|
-
end
|
|
105
|
-
assert_passed(test_result)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def test_should_not_match_parameter_that_does_not_match_regular_expression
|
|
109
|
-
test_result = run_test do
|
|
110
|
-
mock = mock()
|
|
111
|
-
mock.expects(:method).with(regexp_matches(/something different/))
|
|
112
|
-
mock.method('this parameter should not match')
|
|
113
|
-
end
|
|
114
|
-
assert_failed(test_result)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha'
|
|
3
|
-
require 'test_runner'
|
|
4
|
-
|
|
5
|
-
class PartialMockAcceptanceTest < Test::Unit::TestCase
|
|
6
|
-
|
|
7
|
-
include TestRunner
|
|
8
|
-
|
|
9
|
-
def test_should_pass_if_all_expectations_are_satisfied
|
|
10
|
-
test_result = run_test do
|
|
11
|
-
partial_mock_one = "partial_mock_one"
|
|
12
|
-
partial_mock_two = "partial_mock_two"
|
|
13
|
-
|
|
14
|
-
partial_mock_one.expects(:first)
|
|
15
|
-
partial_mock_one.expects(:second)
|
|
16
|
-
partial_mock_two.expects(:third)
|
|
17
|
-
|
|
18
|
-
partial_mock_one.first
|
|
19
|
-
partial_mock_one.second
|
|
20
|
-
partial_mock_two.third
|
|
21
|
-
end
|
|
22
|
-
assert_passed(test_result)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_should_fail_if_all_expectations_are_not_satisfied
|
|
26
|
-
test_result = run_test do
|
|
27
|
-
partial_mock_one = "partial_mock_one"
|
|
28
|
-
partial_mock_two = "partial_mock_two"
|
|
29
|
-
|
|
30
|
-
partial_mock_one.expects(:first)
|
|
31
|
-
partial_mock_one.expects(:second)
|
|
32
|
-
partial_mock_two.expects(:third)
|
|
33
|
-
|
|
34
|
-
partial_mock_one.first
|
|
35
|
-
partial_mock_two.third
|
|
36
|
-
end
|
|
37
|
-
assert_failed(test_result)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha'
|
|
3
|
-
require 'test_runner'
|
|
4
|
-
|
|
5
|
-
class SequenceAcceptanceTest < Test::Unit::TestCase
|
|
6
|
-
|
|
7
|
-
include TestRunner
|
|
8
|
-
|
|
9
|
-
def test_should_constrain_invocations_to_occur_in_expected_order
|
|
10
|
-
test_result = run_test do
|
|
11
|
-
mock = mock()
|
|
12
|
-
sequence = sequence('one')
|
|
13
|
-
|
|
14
|
-
mock.expects(:first).in_sequence(sequence)
|
|
15
|
-
mock.expects(:second).in_sequence(sequence)
|
|
16
|
-
|
|
17
|
-
mock.second
|
|
18
|
-
end
|
|
19
|
-
assert_failed(test_result)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def test_should_allow_invocations_in_sequence
|
|
23
|
-
test_result = run_test do
|
|
24
|
-
mock = mock()
|
|
25
|
-
sequence = sequence('one')
|
|
26
|
-
|
|
27
|
-
mock.expects(:first).in_sequence(sequence)
|
|
28
|
-
mock.expects(:second).in_sequence(sequence)
|
|
29
|
-
|
|
30
|
-
mock.first
|
|
31
|
-
mock.second
|
|
32
|
-
end
|
|
33
|
-
assert_passed(test_result)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_should_constrain_invocations_to_occur_in_expected_order_even_if_expected_on_different_mocks
|
|
37
|
-
test_result = run_test do
|
|
38
|
-
mock_one = mock('1')
|
|
39
|
-
mock_two = mock('2')
|
|
40
|
-
sequence = sequence('one')
|
|
41
|
-
|
|
42
|
-
mock_one.expects(:first).in_sequence(sequence)
|
|
43
|
-
mock_two.expects(:second).in_sequence(sequence)
|
|
44
|
-
|
|
45
|
-
mock_two.second
|
|
46
|
-
end
|
|
47
|
-
assert_failed(test_result)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_should_allow_invocations_in_sequence_even_if_expected_on_different_mocks
|
|
51
|
-
test_result = run_test do
|
|
52
|
-
mock_one = mock('1')
|
|
53
|
-
mock_two = mock('2')
|
|
54
|
-
sequence = sequence('one')
|
|
55
|
-
|
|
56
|
-
mock_one.expects(:first).in_sequence(sequence)
|
|
57
|
-
mock_two.expects(:second).in_sequence(sequence)
|
|
58
|
-
|
|
59
|
-
mock_one.first
|
|
60
|
-
mock_two.second
|
|
61
|
-
end
|
|
62
|
-
assert_passed(test_result)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_should_constrain_invocations_to_occur_in_expected_order_even_if_expected_on_partial_mocks
|
|
66
|
-
test_result = run_test do
|
|
67
|
-
partial_mock_one = "1"
|
|
68
|
-
partial_mock_two = "2"
|
|
69
|
-
sequence = sequence('one')
|
|
70
|
-
|
|
71
|
-
partial_mock_one.expects(:first).in_sequence(sequence)
|
|
72
|
-
partial_mock_two.expects(:second).in_sequence(sequence)
|
|
73
|
-
|
|
74
|
-
partial_mock_two.second
|
|
75
|
-
end
|
|
76
|
-
assert_failed(test_result)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def test_should_allow_invocations_in_sequence_even_if_expected_on_partial_mocks
|
|
80
|
-
test_result = run_test do
|
|
81
|
-
partial_mock_one = "1"
|
|
82
|
-
partial_mock_two = "2"
|
|
83
|
-
sequence = sequence('one')
|
|
84
|
-
|
|
85
|
-
partial_mock_one.expects(:first).in_sequence(sequence)
|
|
86
|
-
partial_mock_two.expects(:second).in_sequence(sequence)
|
|
87
|
-
|
|
88
|
-
partial_mock_one.first
|
|
89
|
-
partial_mock_two.second
|
|
90
|
-
end
|
|
91
|
-
assert_passed(test_result)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def test_should_allow_stub_expectations_to_be_skipped_in_sequence
|
|
95
|
-
test_result = run_test do
|
|
96
|
-
mock = mock()
|
|
97
|
-
sequence = sequence('one')
|
|
98
|
-
|
|
99
|
-
mock.expects(:first).in_sequence(sequence)
|
|
100
|
-
s = mock.stubs(:second).in_sequence(sequence)
|
|
101
|
-
mock.expects(:third).in_sequence(sequence)
|
|
102
|
-
|
|
103
|
-
mock.first
|
|
104
|
-
mock.third
|
|
105
|
-
end
|
|
106
|
-
assert_passed(test_result)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def test_should_regard_sequences_as_independent_of_each_other
|
|
110
|
-
test_result = run_test do
|
|
111
|
-
mock = mock()
|
|
112
|
-
sequence_one = sequence('one')
|
|
113
|
-
sequence_two = sequence('two')
|
|
114
|
-
|
|
115
|
-
mock.expects(:first).in_sequence(sequence_one)
|
|
116
|
-
mock.expects(:second).in_sequence(sequence_one)
|
|
117
|
-
|
|
118
|
-
mock.expects(:third).in_sequence(sequence_two)
|
|
119
|
-
mock.expects(:fourth).in_sequence(sequence_two)
|
|
120
|
-
|
|
121
|
-
mock.first
|
|
122
|
-
mock.third
|
|
123
|
-
mock.second
|
|
124
|
-
mock.fourth
|
|
125
|
-
end
|
|
126
|
-
assert_passed(test_result)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def test_should_include_sequence_in_failure_message
|
|
130
|
-
test_result = run_test do
|
|
131
|
-
mock = mock()
|
|
132
|
-
sequence = sequence('one')
|
|
133
|
-
|
|
134
|
-
mock.expects(:first).in_sequence(sequence)
|
|
135
|
-
mock.expects(:second).in_sequence(sequence)
|
|
136
|
-
|
|
137
|
-
mock.second
|
|
138
|
-
end
|
|
139
|
-
assert_failed(test_result)
|
|
140
|
-
assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def test_should_allow_expectations_to_be_in_more_than_one_sequence
|
|
144
|
-
test_result = run_test do
|
|
145
|
-
mock = mock()
|
|
146
|
-
sequence_one = sequence('one')
|
|
147
|
-
sequence_two = sequence('two')
|
|
148
|
-
|
|
149
|
-
mock.expects(:first).in_sequence(sequence_one)
|
|
150
|
-
mock.expects(:second).in_sequence(sequence_two)
|
|
151
|
-
mock.expects(:three).in_sequence(sequence_one).in_sequence(sequence_two)
|
|
152
|
-
|
|
153
|
-
mock.first
|
|
154
|
-
mock.three
|
|
155
|
-
end
|
|
156
|
-
assert_failed(test_result)
|
|
157
|
-
assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
|
|
158
|
-
assert_match Regexp.new("in sequence 'two'"), test_result.failures.first.message
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def test_should_have_shortcut_for_expectations_to_be_in_more_than_one_sequence
|
|
162
|
-
test_result = run_test do
|
|
163
|
-
mock = mock()
|
|
164
|
-
sequence_one = sequence('one')
|
|
165
|
-
sequence_two = sequence('two')
|
|
166
|
-
|
|
167
|
-
mock.expects(:first).in_sequence(sequence_one)
|
|
168
|
-
mock.expects(:second).in_sequence(sequence_two)
|
|
169
|
-
mock.expects(:three).in_sequence(sequence_one, sequence_two)
|
|
170
|
-
|
|
171
|
-
mock.first
|
|
172
|
-
mock.three
|
|
173
|
-
end
|
|
174
|
-
assert_failed(test_result)
|
|
175
|
-
assert_match Regexp.new("in sequence 'one'"), test_result.failures.first.message
|
|
176
|
-
assert_match Regexp.new("in sequence 'two'"), test_result.failures.first.message
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
end
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha_standalone'
|
|
3
|
-
|
|
4
|
-
class NotATestUnitAssertionFailedError < StandardError
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
class NotATestUnitTestCase
|
|
8
|
-
|
|
9
|
-
include Mocha::Standalone
|
|
10
|
-
|
|
11
|
-
attr_reader :assertion_count
|
|
12
|
-
|
|
13
|
-
def initialize
|
|
14
|
-
@assertion_count = 0
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def run(test_method)
|
|
18
|
-
mocha_setup
|
|
19
|
-
begin
|
|
20
|
-
prepare
|
|
21
|
-
begin
|
|
22
|
-
send(test_method)
|
|
23
|
-
mocha_verify { @assertion_count += 1 }
|
|
24
|
-
rescue Mocha::ExpectationError => e
|
|
25
|
-
new_error = NotATestUnitAssertionFailedError.new(e.message)
|
|
26
|
-
new_error.set_backtrace(e.backtrace)
|
|
27
|
-
raise new_error
|
|
28
|
-
ensure
|
|
29
|
-
cleanup
|
|
30
|
-
end
|
|
31
|
-
ensure
|
|
32
|
-
mocha_teardown
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def prepare
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def cleanup
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
class SampleTest < NotATestUnitTestCase
|
|
45
|
-
|
|
46
|
-
def mocha_with_fulfilled_expectation
|
|
47
|
-
mockee = mock()
|
|
48
|
-
mockee.expects(:blah)
|
|
49
|
-
mockee.blah
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def mocha_with_unfulfilled_expectation
|
|
53
|
-
mockee = mock()
|
|
54
|
-
mockee.expects(:blah)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def mocha_with_unexpected_invocation
|
|
58
|
-
mockee = mock()
|
|
59
|
-
mockee.blah
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def stubba_with_fulfilled_expectation
|
|
63
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
|
64
|
-
stubbee.expects(:blah)
|
|
65
|
-
stubbee.blah
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def stubba_with_unfulfilled_expectation
|
|
69
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
|
70
|
-
stubbee.expects(:blah)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def mocha_with_matching_parameter
|
|
74
|
-
mockee = mock()
|
|
75
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
|
76
|
-
mockee.blah(:wibble => 1)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def mocha_with_non_matching_parameter
|
|
80
|
-
mockee = mock()
|
|
81
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
|
82
|
-
mockee.blah(:wobble => 2)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
require 'test/unit'
|
|
88
|
-
|
|
89
|
-
class StandaloneAcceptanceTest < Test::Unit::TestCase
|
|
90
|
-
|
|
91
|
-
attr_reader :sample_test
|
|
92
|
-
|
|
93
|
-
def setup
|
|
94
|
-
@sample_test = SampleTest.new
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def test_should_pass_mocha_test
|
|
98
|
-
assert_nothing_raised { sample_test.run(:mocha_with_fulfilled_expectation) }
|
|
99
|
-
assert_equal 1, sample_test.assertion_count
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def test_should_fail_mocha_test_due_to_unfulfilled_exception
|
|
103
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unfulfilled_expectation) }
|
|
104
|
-
assert_equal 1, sample_test.assertion_count
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def test_should_fail_mocha_test_due_to_unexpected_invocation
|
|
108
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unexpected_invocation) }
|
|
109
|
-
assert_equal 0, sample_test.assertion_count
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def test_should_pass_stubba_test
|
|
113
|
-
assert_nothing_raised { sample_test.run(:stubba_with_fulfilled_expectation) }
|
|
114
|
-
assert_equal 1, sample_test.assertion_count
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def test_should_fail_stubba_test
|
|
118
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:stubba_with_unfulfilled_expectation) }
|
|
119
|
-
assert_equal 1, sample_test.assertion_count
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def test_should_pass_mocha_test_with_matching_parameter
|
|
123
|
-
assert_nothing_raised { sample_test.run(:mocha_with_matching_parameter) }
|
|
124
|
-
assert_equal 1, sample_test.assertion_count
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def test_should_fail_mocha_test_with_non_matching_parameter
|
|
128
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_non_matching_parameter) }
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
end
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha'
|
|
3
|
-
|
|
4
|
-
class Widget
|
|
5
|
-
|
|
6
|
-
def model
|
|
7
|
-
'original_model'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
class << self
|
|
11
|
-
|
|
12
|
-
def find(options)
|
|
13
|
-
[]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def create(attributes)
|
|
17
|
-
Widget.new
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
module Thingy
|
|
25
|
-
|
|
26
|
-
def self.wotsit
|
|
27
|
-
:hoojamaflip
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
class StubbaAcceptanceTest < Test::Unit::TestCase
|
|
33
|
-
|
|
34
|
-
def test_should_stub_instance_method
|
|
35
|
-
widget = Widget.new
|
|
36
|
-
widget.expects(:model).returns('different_model')
|
|
37
|
-
assert_equal 'different_model', widget.model
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_should_stub_module_method
|
|
41
|
-
should_stub_module_method
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_should_stub_module_method_again
|
|
45
|
-
should_stub_module_method
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_should_stub_class_method
|
|
49
|
-
should_stub_class_method
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def test_should_stub_class_method_again
|
|
53
|
-
should_stub_class_method
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_should_stub_instance_method_on_any_instance_of_a_class
|
|
57
|
-
should_stub_instance_method_on_any_instance_of_a_class
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_should_stub_instance_method_on_any_instance_of_a_class_again
|
|
61
|
-
should_stub_instance_method_on_any_instance_of_a_class
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_should_stub_two_different_class_methods
|
|
65
|
-
should_stub_two_different_class_methods
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_should_stub_two_different_class_methods_again
|
|
69
|
-
should_stub_two_different_class_methods
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
private
|
|
73
|
-
|
|
74
|
-
def should_stub_module_method
|
|
75
|
-
Thingy.expects(:wotsit).returns(:dooda)
|
|
76
|
-
assert_equal :dooda, Thingy.wotsit
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def should_stub_class_method
|
|
80
|
-
widgets = [Widget.new]
|
|
81
|
-
Widget.expects(:find).with(:all).returns(widgets)
|
|
82
|
-
assert_equal widgets, Widget.find(:all)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def should_stub_two_different_class_methods
|
|
86
|
-
found_widgets = [Widget.new]
|
|
87
|
-
created_widget = Widget.new
|
|
88
|
-
Widget.expects(:find).with(:all).returns(found_widgets)
|
|
89
|
-
Widget.expects(:create).with(:model => 'wombat').returns(created_widget)
|
|
90
|
-
assert_equal found_widgets, Widget.find(:all)
|
|
91
|
-
assert_equal created_widget, Widget.create(:model => 'wombat')
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def should_stub_instance_method_on_any_instance_of_a_class
|
|
95
|
-
Widget.any_instance.expects(:model).at_least_once.returns('another_model')
|
|
96
|
-
widget_1 = Widget.new
|
|
97
|
-
widget_2 = Widget.new
|
|
98
|
-
assert_equal 'another_model', widget_1.model
|
|
99
|
-
assert_equal 'another_model', widget_2.model
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
end
|