mocha 0.10.5 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +27 -0
- data/.yardopts +24 -0
- data/CONTRIBUTING.md +7 -0
- data/COPYING.md +3 -0
- data/Gemfile +2 -2
- data/{MIT-LICENSE.rdoc → MIT-LICENSE.md} +1 -1
- data/README.md +363 -0
- data/{RELEASE.rdoc → RELEASE.md} +436 -35
- data/Rakefile +87 -87
- data/gemfiles/Gemfile.minitest.latest +2 -2
- data/gemfiles/Gemfile.test-unit.latest +6 -2
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +12 -45
- data/lib/mocha/api.rb +199 -131
- data/lib/mocha/argument_iterator.rb +6 -10
- data/lib/mocha/backtrace_filter.rb +1 -5
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +77 -66
- data/lib/mocha/central.rb +27 -18
- data/lib/mocha/change_state_side_effect.rb +3 -7
- data/lib/mocha/class_methods.rb +62 -0
- data/lib/mocha/configuration.rb +399 -46
- data/lib/mocha/debug.rb +12 -0
- data/lib/mocha/deprecation.rb +11 -12
- data/lib/mocha/detection/mini_test.rb +23 -0
- data/lib/mocha/detection/test_unit.rb +27 -0
- data/lib/mocha/error_with_filtered_backtrace.rb +13 -0
- data/lib/mocha/exception_raiser.rb +8 -10
- data/lib/mocha/expectation.rb +290 -151
- data/lib/mocha/expectation_error.rb +6 -13
- data/lib/mocha/expectation_error_factory.rb +35 -0
- data/lib/mocha/expectation_list.rb +22 -22
- data/lib/mocha/hooks.rb +42 -0
- data/lib/mocha/in_state_ordering_constraint.rb +3 -7
- data/lib/mocha/inspect.rb +35 -43
- data/lib/mocha/instance_method.rb +12 -21
- data/lib/mocha/integration/assertion_counter.rb +13 -0
- data/lib/mocha/integration/mini_test/adapter.rb +52 -0
- data/lib/mocha/integration/mini_test/exception_translation.rb +1 -7
- data/lib/mocha/integration/mini_test/nothing.rb +19 -0
- data/lib/mocha/integration/mini_test/version_13.rb +35 -25
- data/lib/mocha/integration/mini_test/version_140.rb +35 -26
- data/lib/mocha/integration/mini_test/version_141.rb +43 -34
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +44 -35
- data/lib/mocha/integration/mini_test/version_200.rb +45 -36
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +44 -35
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +70 -0
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +73 -0
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +68 -0
- data/lib/mocha/integration/mini_test.rb +51 -49
- data/lib/mocha/integration/monkey_patcher.rb +24 -0
- data/lib/mocha/integration/test_unit/adapter.rb +50 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +68 -0
- data/lib/mocha/integration/test_unit/nothing.rb +19 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +39 -29
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +40 -30
- data/lib/mocha/integration/test_unit.rb +45 -51
- data/lib/mocha/integration.rb +6 -33
- data/lib/mocha/invocation.rb +77 -0
- data/lib/mocha/is_a.rb +0 -2
- data/lib/mocha/logger.rb +2 -6
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/method_matcher.rb +6 -10
- data/lib/mocha/minitest.rb +8 -0
- data/lib/mocha/mock.rb +266 -79
- data/lib/mocha/mockery.rb +104 -106
- data/lib/mocha/names.rb +10 -20
- data/lib/mocha/not_initialized_error.rb +7 -0
- data/lib/mocha/object_methods.rb +169 -0
- data/lib/mocha/parameter_matchers/all_of.rb +18 -14
- data/lib/mocha/parameter_matchers/any_of.rb +19 -14
- data/lib/mocha/parameter_matchers/any_parameters.rb +14 -13
- data/lib/mocha/parameter_matchers/anything.rb +17 -14
- data/lib/mocha/parameter_matchers/base.rb +33 -31
- data/lib/mocha/parameter_matchers/equals.rb +18 -13
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +58 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +19 -14
- data/lib/mocha/parameter_matchers/has_entry.rb +58 -26
- data/lib/mocha/parameter_matchers/has_key.rb +18 -13
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +18 -13
- data/lib/mocha/parameter_matchers/includes.rb +80 -19
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +18 -13
- data/lib/mocha/parameter_matchers/is_a.rb +20 -14
- data/lib/mocha/parameter_matchers/kind_of.rb +20 -13
- data/lib/mocha/parameter_matchers/not.rb +19 -14
- data/lib/mocha/parameter_matchers/optionally.rb +23 -17
- data/lib/mocha/parameter_matchers/regexp_matches.rb +16 -12
- data/lib/mocha/parameter_matchers/responds_with.rb +17 -11
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +15 -9
- data/lib/mocha/parameter_matchers.rb +4 -5
- data/lib/mocha/parameters_matcher.rb +11 -14
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/receivers.rb +45 -0
- data/lib/mocha/return_values.rb +11 -15
- data/lib/mocha/ruby_version.rb +4 -0
- data/lib/mocha/sequence.rb +21 -17
- data/lib/mocha/setup.rb +14 -0
- data/lib/mocha/single_return_value.rb +5 -8
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/state_machine.rb +69 -67
- data/lib/mocha/stubbed_method.rb +125 -0
- data/lib/mocha/stubbing_error.rb +6 -14
- data/lib/mocha/test_unit.rb +8 -0
- data/lib/mocha/thrower.rb +6 -8
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +12 -22
- data/lib/mocha.rb +8 -3
- data/mocha.gemspec +43 -34
- data/yard-templates/default/layout/html/google_analytics.erb +8 -0
- data/yard-templates/default/layout/html/setup.rb +5 -0
- metadata +123 -268
- data/COPYING.rdoc +0 -3
- data/README.rdoc +0 -54
- data/examples/misc.rb +0 -43
- data/examples/mocha.rb +0 -25
- data/examples/stubba.rb +0 -64
- data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -8
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/lib/mocha/class_method.rb +0 -98
- data/lib/mocha/integration/mini_test/assertion_counter.rb +0 -23
- data/lib/mocha/integration/mini_test/version_230_to_262.rb +0 -59
- data/lib/mocha/integration/test_unit/assertion_counter.rb +0 -23
- data/lib/mocha/integration/test_unit/gem_version_230_to_240.rb +0 -58
- data/lib/mocha/module_method.rb +0 -16
- data/lib/mocha/multiple_yields.rb +0 -20
- data/lib/mocha/no_yields.rb +0 -11
- data/lib/mocha/object.rb +0 -223
- data/lib/mocha/options.rb +0 -1
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/parameter_matchers/query_string.rb +0 -47
- data/lib/mocha/pretty_parameters.rb +0 -28
- data/lib/mocha/single_yield.rb +0 -18
- data/lib/mocha/standalone.rb +0 -1
- data/lib/mocha/unexpected_invocation.rb +0 -18
- data/lib/mocha_standalone.rb +0 -2
- data/lib/stubba.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- data/test/acceptance/api_test.rb +0 -139
- data/test/acceptance/bug_18914_test.rb +0 -43
- data/test/acceptance/bug_21465_test.rb +0 -34
- data/test/acceptance/bug_21563_test.rb +0 -25
- data/test/acceptance/exception_rescue_test.rb +0 -55
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -232
- data/test/acceptance/failure_messages_test.rb +0 -64
- data/test/acceptance/issue_65_test.rb +0 -63
- data/test/acceptance/issue_70_test.rb +0 -55
- data/test/acceptance/minitest_test.rb +0 -162
- data/test/acceptance/mocha_example_test.rb +0 -98
- data/test/acceptance/mocha_test_result_test.rb +0 -84
- data/test/acceptance/mock_test.rb +0 -100
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -51
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -78
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -68
- data/test/acceptance/optional_parameters_test.rb +0 -70
- data/test/acceptance/parameter_matcher_test.rb +0 -300
- data/test/acceptance/partial_mocks_test.rb +0 -47
- data/test/acceptance/raise_exception_test.rb +0 -39
- data/test/acceptance/return_value_test.rb +0 -52
- data/test/acceptance/sequence_test.rb +0 -192
- data/test/acceptance/states_test.rb +0 -70
- data/test/acceptance/stub_any_instance_method_test.rb +0 -198
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -72
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -75
- data/test/acceptance/stub_everything_test.rb +0 -56
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -93
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -69
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -66
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -70
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -72
- data/test/acceptance/stub_module_method_test.rb +0 -163
- data/test/acceptance/stub_test.rb +0 -52
- data/test/acceptance/stubba_example_test.rb +0 -102
- data/test/acceptance/stubba_test.rb +0 -15
- data/test/acceptance/stubba_test_result_test.rb +0 -66
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -65
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -147
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -143
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -64
- data/test/acceptance/throw_test.rb +0 -45
- data/test/acceptance/unstubbing_test.rb +0 -151
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/method_definer.rb +0 -24
- data/test/mini_test_result.rb +0 -83
- data/test/simple_counter.rb +0 -13
- data/test/test_helper.rb +0 -11
- data/test/test_runner.rb +0 -50
- data/test/unit/any_instance_method_test.rb +0 -136
- data/test/unit/array_inspect_test.rb +0 -16
- data/test/unit/backtrace_filter_test.rb +0 -19
- data/test/unit/cardinality_test.rb +0 -56
- data/test/unit/central_test.rb +0 -100
- data/test/unit/change_state_side_effect_test.rb +0 -41
- data/test/unit/class_method_test.rb +0 -260
- data/test/unit/configuration_test.rb +0 -38
- data/test/unit/date_time_inspect_test.rb +0 -21
- data/test/unit/exception_raiser_test.rb +0 -42
- data/test/unit/expectation_list_test.rb +0 -71
- data/test/unit/expectation_test.rb +0 -480
- data/test/unit/hash_inspect_test.rb +0 -16
- data/test/unit/in_state_ordering_constraint_test.rb +0 -43
- data/test/unit/method_matcher_test.rb +0 -23
- data/test/unit/mock_test.rb +0 -312
- data/test/unit/mockery_test.rb +0 -150
- data/test/unit/multiple_yields_test.rb +0 -18
- data/test/unit/no_yields_test.rb +0 -18
- data/test/unit/object_inspect_test.rb +0 -38
- data/test/unit/object_test.rb +0 -87
- 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/equals_test.rb +0 -25
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -96
- data/test/unit/parameter_matchers/has_key_test.rb +0 -55
- data/test/unit/parameter_matchers/has_value_test.rb +0 -57
- data/test/unit/parameter_matchers/includes_test.rb +0 -44
- 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 -46
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -25
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -27
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -25
- 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/single_return_value_test.rb +0 -14
- data/test/unit/single_yield_test.rb +0 -18
- data/test/unit/state_machine_test.rb +0 -98
- data/test/unit/string_inspect_test.rb +0 -11
- data/test/unit/thrower_test.rb +0 -20
- data/test/unit/yield_parameters_test.rb +0 -93
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class ExceptionRescueTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_unexpected_invocation_exception_is_not_caught_by_standard_rescue
|
17
|
-
test_result = run_as_test do
|
18
|
-
mock = mock('mock')
|
19
|
-
begin
|
20
|
-
mock.some_method
|
21
|
-
rescue => e
|
22
|
-
flunk "should not rescue #{e.class}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
assert_failed(test_result)
|
26
|
-
assert_equal "unexpected invocation: #<Mock:mock>.some_method()", test_result.failure_message_lines[0]
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_invocation_never_expected_exception_is_not_caught_by_standard_rescue
|
30
|
-
test_result = run_as_test do
|
31
|
-
mock = mock('mock')
|
32
|
-
mock.expects(:some_method).never
|
33
|
-
begin
|
34
|
-
mock.some_method
|
35
|
-
rescue => e
|
36
|
-
flunk "should not rescue #{e.class}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
assert_failed(test_result)
|
40
|
-
assert_equal "unexpected invocation: #<Mock:mock>.some_method()", test_result.failure_message_lines[0]
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_unsatisfied_expectation_exception_is_not_caught_by_standard_rescue
|
44
|
-
test_result = run_as_test do
|
45
|
-
mock = mock('mock')
|
46
|
-
mock.expects(:some_method)
|
47
|
-
end
|
48
|
-
assert_failed(test_result)
|
49
|
-
assert_equal [
|
50
|
-
"not all expectations were satisfied",
|
51
|
-
"unsatisfied expectations:",
|
52
|
-
"- expected exactly once, not yet invoked: #<Mock:mock>.some_method(any_parameters)"
|
53
|
-
], test_result.failure_message_lines
|
54
|
-
end
|
55
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class ExpectationsOnMultipleMethodsTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_expect_calls_to_multiple_methods
|
17
|
-
instance = Class.new do
|
18
|
-
def my_instance_method_1
|
19
|
-
:original_return_value_1
|
20
|
-
end
|
21
|
-
def my_instance_method_2
|
22
|
-
:original_return_value_2
|
23
|
-
end
|
24
|
-
end.new
|
25
|
-
test_result = run_as_test do
|
26
|
-
instance.expects(
|
27
|
-
:my_instance_method_1 => :new_return_value_1,
|
28
|
-
:my_instance_method_2 => :new_return_value_2
|
29
|
-
)
|
30
|
-
assert_equal :new_return_value_1, instance.my_instance_method_1
|
31
|
-
assert_equal :new_return_value_2, instance.my_instance_method_2
|
32
|
-
end
|
33
|
-
assert_passed(test_result)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_stub_calls_to_multiple_methods
|
37
|
-
instance = Class.new do
|
38
|
-
def my_instance_method_1
|
39
|
-
:original_return_value_1
|
40
|
-
end
|
41
|
-
def my_instance_method_2
|
42
|
-
:original_return_value_2
|
43
|
-
end
|
44
|
-
end.new
|
45
|
-
test_result = run_as_test do
|
46
|
-
instance.stubs(
|
47
|
-
:my_instance_method_1 => :new_return_value_1,
|
48
|
-
:my_instance_method_2 => :new_return_value_2
|
49
|
-
)
|
50
|
-
assert_equal :new_return_value_1, instance.my_instance_method_1
|
51
|
-
assert_equal :new_return_value_2, instance.my_instance_method_2
|
52
|
-
end
|
53
|
-
assert_passed(test_result)
|
54
|
-
end
|
55
|
-
end
|
@@ -1,232 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class ExpectedInvocationCountTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_pass_if_method_is_never_expected_and_is_never_called
|
17
|
-
test_result = run_as_test do
|
18
|
-
mock = mock('mock')
|
19
|
-
mock.expects(:method).never
|
20
|
-
0.times { mock.method }
|
21
|
-
end
|
22
|
-
assert_passed(test_result)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_should_fail_fast_if_method_is_never_expected_but_is_called_once
|
26
|
-
test_result = run_as_test do
|
27
|
-
mock = mock('mock')
|
28
|
-
mock.expects(:method).never
|
29
|
-
1.times { mock.method }
|
30
|
-
end
|
31
|
-
assert_failed(test_result)
|
32
|
-
assert_equal [
|
33
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
34
|
-
"unsatisfied expectations:",
|
35
|
-
"- expected never, invoked once: #<Mock:mock>.method(any_parameters)"
|
36
|
-
], test_result.failure_message_lines
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_should_pass_if_method_is_expected_twice_and_is_called_twice
|
40
|
-
test_result = run_as_test do
|
41
|
-
mock = mock('mock')
|
42
|
-
mock.expects(:method).twice
|
43
|
-
2.times { mock.method }
|
44
|
-
end
|
45
|
-
assert_passed(test_result)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_fail_if_method_is_expected_twice_but_is_called_once
|
49
|
-
test_result = run_as_test do
|
50
|
-
mock = mock('mock')
|
51
|
-
mock.expects(:method).twice
|
52
|
-
1.times { mock.method }
|
53
|
-
end
|
54
|
-
assert_failed(test_result)
|
55
|
-
assert_equal [
|
56
|
-
"not all expectations were satisfied",
|
57
|
-
"unsatisfied expectations:",
|
58
|
-
"- expected exactly twice, invoked once: #<Mock:mock>.method(any_parameters)"
|
59
|
-
], test_result.failure_message_lines
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_should_fail_fast_if_method_is_expected_twice_but_is_called_three_times
|
63
|
-
test_result = run_as_test do
|
64
|
-
mock = mock('mock')
|
65
|
-
mock.expects(:method).twice
|
66
|
-
3.times { mock.method }
|
67
|
-
end
|
68
|
-
assert_failed(test_result)
|
69
|
-
assert_equal [
|
70
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
71
|
-
"unsatisfied expectations:",
|
72
|
-
"- expected exactly twice, invoked 3 times: #<Mock:mock>.method(any_parameters)"
|
73
|
-
], test_result.failure_message_lines
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_twice
|
77
|
-
test_result = run_as_test do
|
78
|
-
mock = mock('mock')
|
79
|
-
mock.expects(:method).times(2..4)
|
80
|
-
2.times { mock.method }
|
81
|
-
end
|
82
|
-
assert_passed(test_result)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_three_times
|
86
|
-
test_result = run_as_test do
|
87
|
-
mock = mock('mock')
|
88
|
-
mock.expects(:method).times(2..4)
|
89
|
-
3.times { mock.method }
|
90
|
-
end
|
91
|
-
assert_passed(test_result)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_four_times
|
95
|
-
test_result = run_as_test do
|
96
|
-
mock = mock('mock')
|
97
|
-
mock.expects(:method).times(2..4)
|
98
|
-
4.times { mock.method }
|
99
|
-
end
|
100
|
-
assert_passed(test_result)
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_should_fail_if_method_is_expected_between_two_and_four_times_and_is_called_once
|
104
|
-
test_result = run_as_test do
|
105
|
-
mock = mock('mock')
|
106
|
-
mock.expects(:method).times(2..4)
|
107
|
-
1.times { mock.method }
|
108
|
-
end
|
109
|
-
assert_failed(test_result)
|
110
|
-
assert_equal [
|
111
|
-
"not all expectations were satisfied",
|
112
|
-
"unsatisfied expectations:",
|
113
|
-
"- expected between 2 and 4 times, invoked once: #<Mock:mock>.method(any_parameters)"
|
114
|
-
], test_result.failure_message_lines
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_should_fail_fast_if_method_is_expected_between_two_and_four_times_and_is_called_five_times
|
118
|
-
test_result = run_as_test do
|
119
|
-
mock = mock('mock')
|
120
|
-
mock.expects(:method).times(2..4)
|
121
|
-
5.times { mock.method }
|
122
|
-
end
|
123
|
-
assert_failed(test_result)
|
124
|
-
assert_equal [
|
125
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
126
|
-
"unsatisfied expectations:",
|
127
|
-
"- expected between 2 and 4 times, invoked 5 times: #<Mock:mock>.method(any_parameters)"
|
128
|
-
], test_result.failure_message_lines
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_should_pass_if_method_is_expected_at_least_once_and_is_called_once
|
132
|
-
test_result = run_as_test do
|
133
|
-
mock = mock('mock')
|
134
|
-
mock.expects(:method).at_least_once
|
135
|
-
1.times { mock.method }
|
136
|
-
end
|
137
|
-
assert_passed(test_result)
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_should_pass_if_method_is_expected_at_least_once_and_is_called_twice
|
141
|
-
test_result = run_as_test do
|
142
|
-
mock = mock('mock')
|
143
|
-
mock.expects(:method).at_least_once
|
144
|
-
2.times { mock.method }
|
145
|
-
end
|
146
|
-
assert_passed(test_result)
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_should_fail_if_method_is_expected_at_least_once_but_is_never_called
|
150
|
-
test_result = run_as_test do
|
151
|
-
mock = mock('mock')
|
152
|
-
mock.expects(:method).at_least_once
|
153
|
-
0.times { mock.method }
|
154
|
-
end
|
155
|
-
assert_failed(test_result)
|
156
|
-
assert_equal [
|
157
|
-
"not all expectations were satisfied",
|
158
|
-
"unsatisfied expectations:",
|
159
|
-
"- expected at least once, not yet invoked: #<Mock:mock>.method(any_parameters)"
|
160
|
-
], test_result.failure_message_lines
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_should_pass_if_method_is_expected_at_most_once_and_is_never_called
|
164
|
-
test_result = run_as_test do
|
165
|
-
mock = mock('mock')
|
166
|
-
mock.expects(:method).at_most_once
|
167
|
-
0.times { mock.method }
|
168
|
-
end
|
169
|
-
assert_passed(test_result)
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_should_pass_if_method_is_expected_at_most_once_and_called_once
|
173
|
-
test_result = run_as_test do
|
174
|
-
mock = mock('mock')
|
175
|
-
mock.expects(:method).at_most_once
|
176
|
-
1.times { mock.method }
|
177
|
-
end
|
178
|
-
assert_passed(test_result)
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_should_fail_fast_if_method_is_expected_at_most_once_but_is_called_twice
|
182
|
-
test_result = run_as_test do
|
183
|
-
mock = mock('mock')
|
184
|
-
mock.expects(:method).at_most_once
|
185
|
-
2.times { mock.method }
|
186
|
-
end
|
187
|
-
assert_failed(test_result)
|
188
|
-
assert_equal [
|
189
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
190
|
-
"unsatisfied expectations:",
|
191
|
-
"- expected at most once, invoked twice: #<Mock:mock>.method(any_parameters)"
|
192
|
-
], test_result.failure_message_lines
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_should_pass_if_method_is_never_expected_and_is_never_called_even_if_everything_is_stubbed
|
196
|
-
test_result = run_as_test do
|
197
|
-
stub = stub_everything('stub')
|
198
|
-
stub.expects(:method).never
|
199
|
-
0.times { stub.method }
|
200
|
-
end
|
201
|
-
assert_passed(test_result)
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_should_fail_fast_if_method_is_never_expected_but_is_called_once_even_if_everything_is_stubbed
|
205
|
-
test_result = run_as_test do
|
206
|
-
stub = stub_everything('stub')
|
207
|
-
stub.expects(:method).never
|
208
|
-
1.times { stub.method }
|
209
|
-
end
|
210
|
-
assert_failed(test_result)
|
211
|
-
assert_equal [
|
212
|
-
"unexpected invocation: #<Mock:stub>.method()",
|
213
|
-
"unsatisfied expectations:",
|
214
|
-
"- expected never, invoked once: #<Mock:stub>.method(any_parameters)"
|
215
|
-
], test_result.failure_message_lines
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_should_fail_fast_if_there_is_no_matching_expectation
|
219
|
-
test_result = run_as_test do
|
220
|
-
mock = mock('mock')
|
221
|
-
mock.expects(:method).with(1)
|
222
|
-
1.times { mock.method }
|
223
|
-
end
|
224
|
-
assert_failed(test_result)
|
225
|
-
assert_equal [
|
226
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
227
|
-
"unsatisfied expectations:",
|
228
|
-
"- expected exactly once, not yet invoked: #<Mock:mock>.method(1)"
|
229
|
-
], test_result.failure_message_lines
|
230
|
-
end
|
231
|
-
|
232
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class FailureMessagesTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}'
|
7
|
-
|
8
|
-
include AcceptanceTest
|
9
|
-
|
10
|
-
def setup
|
11
|
-
setup_acceptance_test
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
teardown_acceptance_test
|
16
|
-
end
|
17
|
-
|
18
|
-
class Foo; end
|
19
|
-
|
20
|
-
def test_should_display_class_name_when_expectation_was_on_class
|
21
|
-
test_result = run_as_test do
|
22
|
-
Foo.expects(:bar)
|
23
|
-
end
|
24
|
-
assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_display_class_name_and_address_when_expectation_was_on_instance
|
28
|
-
test_result = run_as_test do
|
29
|
-
Foo.new.expects(:bar)
|
30
|
-
end
|
31
|
-
assert_match Regexp.new("#<FailureMessagesTest::Foo:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance
|
35
|
-
test_result = run_as_test do
|
36
|
-
Foo.any_instance.expects(:bar)
|
37
|
-
end
|
38
|
-
assert_match Regexp.new('#<AnyInstance:FailureMessagesTest::Foo>'), test_result.failures[0].message
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_should_display_mock_name_when_expectation_was_on_named_mock
|
42
|
-
test_result = run_as_test do
|
43
|
-
foo = mock('foo')
|
44
|
-
foo.expects(:bar)
|
45
|
-
end
|
46
|
-
assert_match Regexp.new('#<Mock:foo>'), test_result.failures[0].message
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_display_mock_address_when_expectation_was_on_unnamed_mock
|
50
|
-
test_result = run_as_test do
|
51
|
-
foo = mock()
|
52
|
-
foo.expects(:bar)
|
53
|
-
end
|
54
|
-
assert_match Regexp.new("#<Mock:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_should_display_string_when_expectation_was_on_string
|
58
|
-
test_result = run_as_test do
|
59
|
-
'Foo'.expects(:bar)
|
60
|
-
end
|
61
|
-
assert_match Regexp.new("'Foo'"), test_result.failures[0].message
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class Issue65Test < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_expectations_on_class_methods_on_same_class_should_be_verified_in_consecutive_tests
|
17
|
-
klass = Class.new do
|
18
|
-
def self.foo; end
|
19
|
-
def self.bar; end
|
20
|
-
end
|
21
|
-
test_1 = run_as_test do
|
22
|
-
klass.expects(:foo)
|
23
|
-
klass.foo
|
24
|
-
end
|
25
|
-
assert_passed(test_1)
|
26
|
-
test_2 = run_as_test do
|
27
|
-
klass.expects(:bar)
|
28
|
-
end
|
29
|
-
assert_failed(test_2)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_expectations_on_any_instance_methods_on_same_class_should_be_verified_in_consecutive_tests
|
33
|
-
klass = Class.new do
|
34
|
-
def foo; end
|
35
|
-
def bar; end
|
36
|
-
end
|
37
|
-
test_1 = run_as_test do
|
38
|
-
klass.any_instance.expects(:foo)
|
39
|
-
klass.new.foo
|
40
|
-
end
|
41
|
-
assert_passed(test_1)
|
42
|
-
test_2 = run_as_test do
|
43
|
-
klass.any_instance.expects(:bar)
|
44
|
-
end
|
45
|
-
assert_failed(test_2)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_expectations_on_instance_methods_on_same_object_should_be_verified_in_consecutive_tests
|
49
|
-
instance = Class.new do
|
50
|
-
def foo; end
|
51
|
-
def bar; end
|
52
|
-
end.new
|
53
|
-
test_1 = run_as_test do
|
54
|
-
instance.expects(:foo)
|
55
|
-
instance.foo
|
56
|
-
end
|
57
|
-
assert_passed(test_1)
|
58
|
-
test_2 = run_as_test do
|
59
|
-
instance.expects(:bar)
|
60
|
-
end
|
61
|
-
assert_failed(test_2)
|
62
|
-
end
|
63
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class Issue70Test < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_stub_expectations_instance_method
|
17
|
-
instance = Class.new do
|
18
|
-
def expectations
|
19
|
-
:original_return_value
|
20
|
-
end
|
21
|
-
end.new
|
22
|
-
test_result = run_as_test do
|
23
|
-
instance.stubs(:expectations).returns(:stubbed_return_value)
|
24
|
-
assert_equal :stubbed_return_value, instance.expectations
|
25
|
-
end
|
26
|
-
assert_passed(test_result)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_stub_expectations_class_method
|
30
|
-
klass = Class.new do
|
31
|
-
def self.expectations
|
32
|
-
:original_return_value
|
33
|
-
end
|
34
|
-
end
|
35
|
-
test_result = run_as_test do
|
36
|
-
klass.stubs(:expectations).returns(:stubbed_return_value)
|
37
|
-
assert_equal :stubbed_return_value, klass.expectations
|
38
|
-
end
|
39
|
-
assert_passed(test_result)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_stub_expectations_any_instance_method
|
43
|
-
klass = Class.new do
|
44
|
-
def expectations
|
45
|
-
:original_return_value
|
46
|
-
end
|
47
|
-
end
|
48
|
-
instance = klass.new
|
49
|
-
test_result = run_as_test do
|
50
|
-
klass.any_instance.stubs(:expectations).returns(:stubbed_return_value)
|
51
|
-
assert_equal :stubbed_return_value, instance.expectations
|
52
|
-
end
|
53
|
-
assert_passed(test_result)
|
54
|
-
end
|
55
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
|
3
|
-
if defined?(MiniTest)
|
4
|
-
$stderr.puts "TODO: Running suite with MiniTest, running the MiniTestAdapterTest results in an error so skipping it for now."
|
5
|
-
else
|
6
|
-
begin
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'minitest'
|
9
|
-
rescue Gem::LoadError
|
10
|
-
# MiniTest gem not available
|
11
|
-
end
|
12
|
-
|
13
|
-
begin
|
14
|
-
require 'minitest/unit'
|
15
|
-
rescue LoadError
|
16
|
-
# MiniTest not available
|
17
|
-
end
|
18
|
-
|
19
|
-
if defined?(MiniTest)
|
20
|
-
|
21
|
-
# monkey-patch MiniTest now that it has hopefully been loaded
|
22
|
-
require 'mocha/integration/mini_test'
|
23
|
-
|
24
|
-
class MiniTestSampleTest < MiniTest::Unit::TestCase
|
25
|
-
|
26
|
-
def test_mocha_with_fulfilled_expectation
|
27
|
-
mockee = mock()
|
28
|
-
mockee.expects(:blah)
|
29
|
-
mockee.blah
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_mocha_with_unfulfilled_expectation
|
33
|
-
mockee = mock()
|
34
|
-
mockee.expects(:blah)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_mocha_with_unexpected_invocation
|
38
|
-
mockee = mock()
|
39
|
-
mockee.blah
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_stubba_with_fulfilled_expectation
|
43
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
44
|
-
stubbee.expects(:blah)
|
45
|
-
stubbee.blah
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_stubba_with_unfulfilled_expectation
|
49
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
50
|
-
stubbee.expects(:blah)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_mocha_with_matching_parameter
|
54
|
-
mockee = mock()
|
55
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
56
|
-
mockee.blah(:wibble => 1)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_mocha_with_non_matching_parameter
|
60
|
-
mockee = mock()
|
61
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
62
|
-
mockee.blah(:wobble => 2)
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
class MiniTestTest < Test::Unit::TestCase
|
68
|
-
|
69
|
-
def setup
|
70
|
-
@output = StringIO.new
|
71
|
-
MiniTest::Unit.output = @output
|
72
|
-
@runner = MiniTest::Unit.new
|
73
|
-
end
|
74
|
-
|
75
|
-
attr_reader :runner
|
76
|
-
|
77
|
-
def test_should_pass_mocha_test
|
78
|
-
run_test :test_mocha_with_fulfilled_expectation
|
79
|
-
|
80
|
-
assert_equal 0, runner.failures
|
81
|
-
assert_equal 0, runner.errors
|
82
|
-
assert_equal 1, runner.assertion_count
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_should_fail_mocha_test_due_to_unfulfilled_expectation
|
86
|
-
run_test :test_mocha_with_unfulfilled_expectation
|
87
|
-
|
88
|
-
assert_equal 1, runner.failures
|
89
|
-
assert_equal 0, runner.errors
|
90
|
-
assert_equal 1, runner.assertion_count
|
91
|
-
assert_not_all_expectation_were_satisfied
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_should_fail_mocha_test_due_to_unexpected_invocation
|
95
|
-
run_test :test_mocha_with_unexpected_invocation
|
96
|
-
|
97
|
-
assert_equal 1, runner.failures
|
98
|
-
assert_equal 0, runner.errors
|
99
|
-
assert_equal 0, runner.assertion_count
|
100
|
-
assert_unexpected_invocation
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_should_pass_stubba_test
|
104
|
-
run_test :test_stubba_with_fulfilled_expectation
|
105
|
-
|
106
|
-
assert_equal 0, runner.failures
|
107
|
-
assert_equal 0, runner.errors
|
108
|
-
assert_equal 1, runner.assertion_count
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_should_fail_stubba_test_due_to_unfulfilled_expectation
|
112
|
-
run_test :test_stubba_with_unfulfilled_expectation
|
113
|
-
|
114
|
-
assert_equal 1, runner.failures
|
115
|
-
assert_equal 0, runner.errors
|
116
|
-
assert_equal 1, runner.assertion_count
|
117
|
-
assert_not_all_expectation_were_satisfied
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_should_pass_mocha_test_with_matching_parameter
|
121
|
-
run_test :test_mocha_with_matching_parameter
|
122
|
-
|
123
|
-
assert_equal 0, runner.failures
|
124
|
-
assert_equal 0, runner.errors
|
125
|
-
assert_equal 1, runner.assertion_count
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_should_fail_mocha_test_with_non_matching_parameter
|
129
|
-
run_test :test_mocha_with_non_matching_parameter
|
130
|
-
|
131
|
-
assert_equal 1, runner.failures
|
132
|
-
assert_equal 0, runner.errors
|
133
|
-
assert_equal 0, runner.assertion_count # unexpected invocation occurs before expectation is verified
|
134
|
-
assert_unexpected_invocation
|
135
|
-
end
|
136
|
-
|
137
|
-
private
|
138
|
-
|
139
|
-
def run_test(method_name)
|
140
|
-
run_method = (MiniTest::Unit::VERSION >= "2.1.0") ? :_run : :run
|
141
|
-
runner.send(run_method, ["-n", method_name.to_s])
|
142
|
-
end
|
143
|
-
|
144
|
-
def output
|
145
|
-
@output.rewind
|
146
|
-
@output.read
|
147
|
-
end
|
148
|
-
|
149
|
-
def assert_unexpected_invocation
|
150
|
-
assert_match Regexp.new('unexpected invocation'), output, "MiniTest output:\n#{output}"
|
151
|
-
end
|
152
|
-
|
153
|
-
def assert_not_all_expectation_were_satisfied
|
154
|
-
assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}"
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
else
|
160
|
-
$stderr.puts "MiniTest is not available, so MiniTestAdapterTest has not been run."
|
161
|
-
end
|
162
|
-
end
|