mocha 1.11.2 → 1.12.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 +4 -4
 - data/CONTRIBUTING.md +1 -1
 - data/README.md +28 -30
 - data/RELEASE.md +25 -0
 - data/Rakefile +6 -1
 - data/lib/mocha/cardinality.rb +30 -27
 - data/lib/mocha/expectation.rb +24 -24
 - data/lib/mocha/mock.rb +1 -1
 - data/lib/mocha/mockery.rb +9 -22
 - data/lib/mocha/state_machine.rb +30 -38
 - data/lib/mocha/version.rb +1 -1
 - data/mocha.gemspec +3 -1
 - metadata +5 -192
 - data/docs/CNAME +0 -1
 - data/docs/Mocha.html +0 -254
 - data/docs/Mocha/API.html +0 -1285
 - data/docs/Mocha/ClassMethods.html +0 -264
 - data/docs/Mocha/Configuration.html +0 -1525
 - data/docs/Mocha/Expectation.html +0 -2862
 - data/docs/Mocha/ExpectationError.html +0 -152
 - data/docs/Mocha/ExpectationErrorFactory.html +0 -260
 - data/docs/Mocha/Hooks.html +0 -370
 - data/docs/Mocha/Integration.html +0 -125
 - data/docs/Mocha/Integration/MiniTest.html +0 -123
 - data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
 - data/docs/Mocha/Integration/TestUnit.html +0 -123
 - data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
 - data/docs/Mocha/Mock.html +0 -1210
 - data/docs/Mocha/ObjectMethods.html +0 -765
 - data/docs/Mocha/ParameterMatchers.html +0 -2949
 - data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
 - data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
 - data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
 - data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
 - data/docs/Mocha/ParameterMatchers/Base.html +0 -441
 - data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
 - data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
 - data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
 - data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
 - data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
 - data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
 - data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
 - data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
 - data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
 - data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
 - data/docs/Mocha/ParameterMatchers/Not.html +0 -153
 - data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
 - data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
 - data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
 - data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
 - data/docs/Mocha/Sequence.html +0 -149
 - data/docs/Mocha/StateMachine.html +0 -527
 - data/docs/Mocha/StateMachine/State.html +0 -140
 - data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
 - data/docs/Mocha/StubbingError.html +0 -150
 - data/docs/_index.html +0 -519
 - data/docs/class_list.html +0 -51
 - data/docs/css/common.css +0 -1
 - data/docs/css/full_list.css +0 -58
 - data/docs/css/style.css +0 -496
 - data/docs/file.COPYING.html +0 -81
 - data/docs/file.MIT-LICENSE.html +0 -85
 - data/docs/file.README.html +0 -448
 - data/docs/file.RELEASE.html +0 -1028
 - data/docs/file_list.html +0 -71
 - data/docs/frames.html +0 -17
 - data/docs/index.html +0 -448
 - data/docs/js/app.js +0 -303
 - data/docs/js/full_list.js +0 -216
 - data/docs/js/jquery.js +0 -4
 - data/docs/method_list.html +0 -651
 - data/docs/top-level-namespace.html +0 -118
 - data/test/acceptance/acceptance_test_helper.rb +0 -42
 - data/test/acceptance/bug_18914_test.rb +0 -37
 - data/test/acceptance/bug_21465_test.rb +0 -31
 - data/test/acceptance/bug_21563_test.rb +0 -22
 - data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
 - data/test/acceptance/exception_rescue_test.rb +0 -53
 - data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
 - data/test/acceptance/expected_invocation_count_test.rb +0 -229
 - data/test/acceptance/failure_messages_test.rb +0 -77
 - data/test/acceptance/issue_272_test.rb +0 -50
 - data/test/acceptance/issue_457_test.rb +0 -31
 - data/test/acceptance/issue_65_test.rb +0 -64
 - data/test/acceptance/issue_70_test.rb +0 -53
 - data/test/acceptance/mocha_example_test.rb +0 -106
 - data/test/acceptance/mocha_test_result_test.rb +0 -83
 - data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -98
 - data/test/acceptance/mock_test.rb +0 -191
 - data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
 - data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
 - data/test/acceptance/multiple_yielding_test.rb +0 -59
 - data/test/acceptance/optional_parameters_test.rb +0 -67
 - data/test/acceptance/parameter_matcher_test.rb +0 -299
 - data/test/acceptance/partial_mocks_test.rb +0 -44
 - data/test/acceptance/prepend_test.rb +0 -86
 - data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
 - data/test/acceptance/raise_exception_test.rb +0 -36
 - data/test/acceptance/return_value_test.rb +0 -49
 - data/test/acceptance/sequence_test.rb +0 -189
 - data/test/acceptance/states_test.rb +0 -71
 - data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
 - data/test/acceptance/stub_any_instance_method_test.rb +0 -301
 - data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
 - data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
 - data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
 - data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
 - data/test/acceptance/stub_everything_test.rb +0 -53
 - data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
 - data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
 - data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
 - data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
 - data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
 - 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 -67
 - data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
 - data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
 - data/test/acceptance/stub_module_method_test.rb +0 -200
 - data/test/acceptance/stub_test.rb +0 -49
 - data/test/acceptance/stubba_example_test.rb +0 -103
 - data/test/acceptance/stubba_test_result_test.rb +0 -71
 - data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
 - data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
 - data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
 - data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
 - data/test/acceptance/stubbing_nil_test.rb +0 -60
 - data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
 - data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
 - data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
 - data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
 - data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
 - data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
 - data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
 - data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
 - data/test/acceptance/throw_test.rb +0 -42
 - data/test/acceptance/unexpected_invocation_test.rb +0 -23
 - data/test/acceptance/unstubbing_test.rb +0 -194
 - data/test/acceptance/yielding_test.rb +0 -80
 - data/test/assertions.rb +0 -8
 - data/test/deprecation_disabler.rb +0 -15
 - data/test/execution_point.rb +0 -36
 - data/test/integration/mini_test_test.rb +0 -8
 - data/test/integration/shared_tests.rb +0 -178
 - data/test/integration/test_unit_test.rb +0 -8
 - data/test/method_definer.rb +0 -16
 - data/test/mini_test_result.rb +0 -96
 - data/test/minitest_result.rb +0 -48
 - data/test/simple_counter.rb +0 -11
 - data/test/test_helper.rb +0 -58
 - data/test/test_runner.rb +0 -58
 - data/test/test_unit_result.rb +0 -22
 - data/test/unit/any_instance_method_test.rb +0 -175
 - data/test/unit/array_inspect_test.rb +0 -14
 - data/test/unit/backtrace_filter_test.rb +0 -17
 - data/test/unit/cardinality_test.rb +0 -72
 - data/test/unit/central_test.rb +0 -98
 - data/test/unit/change_state_side_effect_test.rb +0 -37
 - data/test/unit/class_methods_test.rb +0 -69
 - data/test/unit/configuration_test.rb +0 -37
 - data/test/unit/date_time_inspect_test.rb +0 -19
 - data/test/unit/exception_raiser_test.rb +0 -45
 - data/test/unit/expectation_list_test.rb +0 -82
 - data/test/unit/expectation_test.rb +0 -504
 - data/test/unit/hash_inspect_test.rb +0 -14
 - data/test/unit/hooks_test.rb +0 -35
 - data/test/unit/in_state_ordering_constraint_test.rb +0 -39
 - data/test/unit/instance_method_test.rb +0 -282
 - data/test/unit/method_matcher_test.rb +0 -26
 - data/test/unit/mock_test.rb +0 -372
 - data/test/unit/mockery_test.rb +0 -171
 - data/test/unit/module_methods_test.rb +0 -16
 - data/test/unit/object_inspect_test.rb +0 -60
 - data/test/unit/object_methods_test.rb +0 -63
 - data/test/unit/parameter_matchers/all_of_test.rb +0 -24
 - data/test/unit/parameter_matchers/any_of_test.rb +0 -24
 - data/test/unit/parameter_matchers/anything_test.rb +0 -19
 - data/test/unit/parameter_matchers/equals_test.rb +0 -23
 - data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
 - data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
 - data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
 - data/test/unit/parameter_matchers/has_key_test.rb +0 -54
 - data/test/unit/parameter_matchers/has_value_test.rb +0 -55
 - data/test/unit/parameter_matchers/includes_test.rb +0 -106
 - data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
 - data/test/unit/parameter_matchers/is_a_test.rb +0 -23
 - data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
 - data/test/unit/parameter_matchers/not_test.rb +0 -24
 - data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
 - data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
 - data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
 - data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
 - data/test/unit/parameters_matcher_test.rb +0 -119
 - data/test/unit/receivers_test.rb +0 -96
 - data/test/unit/return_values_test.rb +0 -66
 - data/test/unit/sequence_test.rb +0 -100
 - data/test/unit/single_return_value_test.rb +0 -17
 - data/test/unit/state_machine_test.rb +0 -96
 - data/test/unit/string_inspect_test.rb +0 -9
 - data/test/unit/thrower_test.rb +0 -23
 - data/test/unit/yield_parameters_test.rb +0 -73
 
| 
         @@ -1,37 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path('../../test_helper', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'mocha/change_state_side_effect'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            class ChangeStateSideEffectTest < Mocha::TestCase
         
     | 
| 
       6 
     | 
    
         
            -
              include Mocha
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              class FakeState
         
     | 
| 
       9 
     | 
    
         
            -
                attr_reader :active
         
     | 
| 
       10 
     | 
    
         
            -
                attr_writer :description
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                def activate
         
     | 
| 
       13 
     | 
    
         
            -
                  @active = true
         
     | 
| 
       14 
     | 
    
         
            -
                end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                def mocha_inspect
         
     | 
| 
       17 
     | 
    
         
            -
                  @description
         
     | 
| 
       18 
     | 
    
         
            -
                end
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              def test_should_activate_the_given_state
         
     | 
| 
       22 
     | 
    
         
            -
                state = FakeState.new
         
     | 
| 
       23 
     | 
    
         
            -
                side_effect = ChangeStateSideEffect.new(state)
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                side_effect.perform
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                assert state.active
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
              def test_should_describe_itself_in_terms_of_the_activated_state
         
     | 
| 
       31 
     | 
    
         
            -
                state = FakeState.new
         
     | 
| 
       32 
     | 
    
         
            -
                state.description = 'the-new-state'
         
     | 
| 
       33 
     | 
    
         
            -
                side_effect = ChangeStateSideEffect.new(state)
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                assert_equal 'then the-new-state', side_effect.mocha_inspect
         
     | 
| 
       36 
     | 
    
         
            -
              end
         
     | 
| 
       37 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,69 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path('../../test_helper', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
            require 'mocha/class_methods'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'mocha/object_methods'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'mocha/mockery'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'mocha/names'
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            class ClassMethodsTest < Mocha::TestCase
         
     | 
| 
       8 
     | 
    
         
            -
              def setup
         
     | 
| 
       9 
     | 
    
         
            -
                Mocha::Mockery.setup
         
     | 
| 
       10 
     | 
    
         
            -
                @klass = Class.new.extend(Mocha::ClassMethods, Mocha::ObjectMethods)
         
     | 
| 
       11 
     | 
    
         
            -
              end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
              def teardown
         
     | 
| 
       14 
     | 
    
         
            -
                Mocha::Mockery.teardown
         
     | 
| 
       15 
     | 
    
         
            -
              end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
              def test_should_build_any_instance_object
         
     | 
| 
       18 
     | 
    
         
            -
                any_instance = @klass.any_instance
         
     | 
| 
       19 
     | 
    
         
            -
                assert_not_nil any_instance
         
     | 
| 
       20 
     | 
    
         
            -
                assert any_instance.is_a?(Mocha::ClassMethods::AnyInstance)
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              def test_should_return_same_any_instance_object
         
     | 
| 
       24 
     | 
    
         
            -
                any_instance1 = @klass.any_instance
         
     | 
| 
       25 
     | 
    
         
            -
                any_instance2 = @klass.any_instance
         
     | 
| 
       26 
     | 
    
         
            -
                assert_equal any_instance1, any_instance2
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              def test_any_instance_should_build_mocha_referring_to_klass
         
     | 
| 
       30 
     | 
    
         
            -
                mocha = @klass.any_instance.mocha
         
     | 
| 
       31 
     | 
    
         
            -
                assert_not_nil mocha
         
     | 
| 
       32 
     | 
    
         
            -
                assert mocha.is_a?(Mocha::Mock)
         
     | 
| 
       33 
     | 
    
         
            -
                expected_name = Mocha::ImpersonatingAnyInstanceName.new(@klass).mocha_inspect
         
     | 
| 
       34 
     | 
    
         
            -
                assert_equal expected_name, mocha.mocha_inspect
         
     | 
| 
       35 
     | 
    
         
            -
              end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
              def test_any_instance_should_not_build_mocha_if_instantiate_is_false
         
     | 
| 
       38 
     | 
    
         
            -
                assert_nil @klass.any_instance.mocha(false)
         
     | 
| 
       39 
     | 
    
         
            -
              end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
              def test_any_instance_should_reuse_existing_mocha
         
     | 
| 
       42 
     | 
    
         
            -
                mocha1 = @klass.any_instance.mocha
         
     | 
| 
       43 
     | 
    
         
            -
                mocha2 = @klass.any_instance.mocha
         
     | 
| 
       44 
     | 
    
         
            -
                assert_equal mocha1, mocha2
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
              def test_any_instance_should_reuse_existing_mocha_even_if_instantiate_is_false
         
     | 
| 
       48 
     | 
    
         
            -
                mocha1 = @klass.any_instance.mocha
         
     | 
| 
       49 
     | 
    
         
            -
                mocha2 = @klass.any_instance.mocha(false)
         
     | 
| 
       50 
     | 
    
         
            -
                assert_equal mocha1, mocha2
         
     | 
| 
       51 
     | 
    
         
            -
              end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
              def test_should_use_stubba_class_method_for_class
         
     | 
| 
       54 
     | 
    
         
            -
                assert_equal Mocha::InstanceMethod, @klass.stubba_method
         
     | 
| 
       55 
     | 
    
         
            -
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
              def test_should_use_stubba_class_method_for_any_instance
         
     | 
| 
       58 
     | 
    
         
            -
                assert_equal Mocha::AnyInstanceMethod, @klass.any_instance.stubba_method
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
              def test_should_stub_self_for_class
         
     | 
| 
       62 
     | 
    
         
            -
                assert_equal @klass, @klass.stubba_object
         
     | 
| 
       63 
     | 
    
         
            -
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
              def test_should_stub_relevant_class_for_any_instance
         
     | 
| 
       66 
     | 
    
         
            -
                any_instance = @klass.any_instance
         
     | 
| 
       67 
     | 
    
         
            -
                assert_equal @klass, any_instance.stubba_object
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,37 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path('../../test_helper', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
            require 'mocha/configuration'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            class ConfigurationTest < Mocha::TestCase
         
     | 
| 
       5 
     | 
    
         
            -
              def test_allow_temporarily_changes_config_when_given_block
         
     | 
| 
       6 
     | 
    
         
            -
                Mocha.configure { |c| c.stubbing_method_unnecessarily = :warn }
         
     | 
| 
       7 
     | 
    
         
            -
                yielded = false
         
     | 
| 
       8 
     | 
    
         
            -
                Mocha::Configuration.override(:stubbing_method_unnecessarily => :allow) do
         
     | 
| 
       9 
     | 
    
         
            -
                  yielded = true
         
     | 
| 
       10 
     | 
    
         
            -
                  assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
         
     | 
| 
       11 
     | 
    
         
            -
                end
         
     | 
| 
       12 
     | 
    
         
            -
                assert yielded
         
     | 
| 
       13 
     | 
    
         
            -
                assert_equal :warn, Mocha.configuration.stubbing_method_unnecessarily
         
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
              def test_prevent_temporarily_changes_config_when_given_block
         
     | 
| 
       17 
     | 
    
         
            -
                Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
         
     | 
| 
       18 
     | 
    
         
            -
                yielded = false
         
     | 
| 
       19 
     | 
    
         
            -
                Mocha::Configuration.override(:stubbing_method_unnecessarily => :prevent) do
         
     | 
| 
       20 
     | 
    
         
            -
                  yielded = true
         
     | 
| 
       21 
     | 
    
         
            -
                  assert_equal :prevent, Mocha.configuration.stubbing_method_unnecessarily
         
     | 
| 
       22 
     | 
    
         
            -
                end
         
     | 
| 
       23 
     | 
    
         
            -
                assert yielded
         
     | 
| 
       24 
     | 
    
         
            -
                assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
         
     | 
| 
       25 
     | 
    
         
            -
              end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              def test_warn_when_temporarily_changes_config_when_given_block
         
     | 
| 
       28 
     | 
    
         
            -
                Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
         
     | 
| 
       29 
     | 
    
         
            -
                yielded = false
         
     | 
| 
       30 
     | 
    
         
            -
                Mocha::Configuration.override(:stubbing_method_unnecessarily => :warn) do
         
     | 
| 
       31 
     | 
    
         
            -
                  yielded = true
         
     | 
| 
       32 
     | 
    
         
            -
                  assert_equal :warn, Mocha.configuration.stubbing_method_unnecessarily
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
                assert yielded
         
     | 
| 
       35 
     | 
    
         
            -
                assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
         
     | 
| 
       36 
     | 
    
         
            -
              end
         
     | 
| 
       37 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,19 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path('../../test_helper', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
            require 'mocha/inspect'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            class DateTimeInspectTest < Mocha::TestCase
         
     | 
| 
       5 
     | 
    
         
            -
              def test_should_use_include_date_in_seconds
         
     | 
| 
       6 
     | 
    
         
            -
                time = Time.now
         
     | 
| 
       7 
     | 
    
         
            -
                assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
         
     | 
| 
       8 
     | 
    
         
            -
              end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              def test_should_use_to_s_for_date
         
     | 
| 
       11 
     | 
    
         
            -
                date = Date.new(2006, 1, 1)
         
     | 
| 
       12 
     | 
    
         
            -
                assert_equal date.to_s, date.mocha_inspect
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              def test_should_use_to_s_for_datetime
         
     | 
| 
       16 
     | 
    
         
            -
                datetime = DateTime.new(2006, 1, 1) # rubocop:disable Style/DateTime
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal datetime.to_s, datetime.mocha_inspect
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,45 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path('../../test_helper', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'mocha/invocation'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'mocha/exception_raiser'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'timeout'
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            class ExceptionRaiserTest < Mocha::TestCase
         
     | 
| 
       8 
     | 
    
         
            -
              include Mocha
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              def new_invocation
         
     | 
| 
       11 
     | 
    
         
            -
                Invocation.new(:irrelevant, :irrelevant)
         
     | 
| 
       12 
     | 
    
         
            -
              end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
              def test_should_raise_exception_with_specified_class_and_default_message
         
     | 
| 
       15 
     | 
    
         
            -
                exception_class = Class.new(StandardError)
         
     | 
| 
       16 
     | 
    
         
            -
                raiser = ExceptionRaiser.new(exception_class, nil)
         
     | 
| 
       17 
     | 
    
         
            -
                exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
         
     | 
| 
       18 
     | 
    
         
            -
                assert_equal exception_class.to_s, exception.message
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              def test_should_raise_exception_with_specified_class_and_message
         
     | 
| 
       22 
     | 
    
         
            -
                exception_class = Class.new(StandardError)
         
     | 
| 
       23 
     | 
    
         
            -
                raiser = ExceptionRaiser.new(exception_class, 'message')
         
     | 
| 
       24 
     | 
    
         
            -
                exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
         
     | 
| 
       25 
     | 
    
         
            -
                assert_equal 'message', exception.message
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
              def test_should_raise_exception_instance
         
     | 
| 
       29 
     | 
    
         
            -
                exception_class = Class.new(StandardError)
         
     | 
| 
       30 
     | 
    
         
            -
                raiser = ExceptionRaiser.new(exception_class.new('message'), nil)
         
     | 
| 
       31 
     | 
    
         
            -
                exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
         
     | 
| 
       32 
     | 
    
         
            -
                assert_equal 'message', exception.message
         
     | 
| 
       33 
     | 
    
         
            -
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
              def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
         
     | 
| 
       36 
     | 
    
         
            -
                raiser = ExceptionRaiser.new(Interrupt, nil)
         
     | 
| 
       37 
     | 
    
         
            -
                assert_raises(Interrupt) { raiser.evaluate(new_invocation) }
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
         
     | 
| 
       41 
     | 
    
         
            -
                exception_class = Class.new(Interrupt)
         
     | 
| 
       42 
     | 
    
         
            -
                raiser = ExceptionRaiser.new(exception_class, nil)
         
     | 
| 
       43 
     | 
    
         
            -
                assert_raises(exception_class) { raiser.evaluate(new_invocation) }
         
     | 
| 
       44 
     | 
    
         
            -
              end
         
     | 
| 
       45 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,82 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path('../../test_helper', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
            require 'mocha/expectation_list'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'mocha/expectation'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'mocha/invocation'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'set'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'method_definer'
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            class ExpectationListTest < Mocha::TestCase
         
     | 
| 
       9 
     | 
    
         
            -
              include MethodDefiner
         
     | 
| 
       10 
     | 
    
         
            -
              include Mocha
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
              def test_should_return_added_expectation
         
     | 
| 
       13 
     | 
    
         
            -
                expectation_list = ExpectationList.new
         
     | 
| 
       14 
     | 
    
         
            -
                expectation = Expectation.new(nil, :my_method)
         
     | 
| 
       15 
     | 
    
         
            -
                assert_same expectation, expectation_list.add(expectation)
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
              def test_should_find_matching_expectation
         
     | 
| 
       19 
     | 
    
         
            -
                expectation_list = ExpectationList.new
         
     | 
| 
       20 
     | 
    
         
            -
                expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
         
     | 
| 
       21 
     | 
    
         
            -
                expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
         
     | 
| 
       22 
     | 
    
         
            -
                expectation_list.add(expectation1)
         
     | 
| 
       23 
     | 
    
         
            -
                expectation_list.add(expectation2)
         
     | 
| 
       24 
     | 
    
         
            -
                assert_same expectation1, expectation_list.match(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
         
     | 
| 
       25 
     | 
    
         
            -
              end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              def test_should_remove_all_expectations_matching_method_name
         
     | 
| 
       28 
     | 
    
         
            -
                expectation_list = ExpectationList.new
         
     | 
| 
       29 
     | 
    
         
            -
                expectation1 = Expectation.new(nil, :method_one).with(:argument1, :argument2)
         
     | 
| 
       30 
     | 
    
         
            -
                expectation2 = Expectation.new(nil, :method_one).with(:argument3, :argument4)
         
     | 
| 
       31 
     | 
    
         
            -
                expectation3 = Expectation.new(nil, :method_two)
         
     | 
| 
       32 
     | 
    
         
            -
                expectation_list.add(expectation1)
         
     | 
| 
       33 
     | 
    
         
            -
                expectation_list.add(expectation2)
         
     | 
| 
       34 
     | 
    
         
            -
                expectation_list.add(expectation3)
         
     | 
| 
       35 
     | 
    
         
            -
                expectation_list.remove_all_matching_method(:method_one)
         
     | 
| 
       36 
     | 
    
         
            -
                assert_nil expectation_list.match(Invocation.new(:irrelevant, :method_one, :argument1, :argument2))
         
     | 
| 
       37 
     | 
    
         
            -
                assert_nil expectation_list.match(Invocation.new(:irrelevant, :method_one, :argument3, :argument4))
         
     | 
| 
       38 
     | 
    
         
            -
                assert_same expectation3, expectation_list.match(Invocation.new(:irrelevant, :method_two))
         
     | 
| 
       39 
     | 
    
         
            -
              end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
              def test_should_find_most_recent_matching_expectation
         
     | 
| 
       42 
     | 
    
         
            -
                expectation_list = ExpectationList.new
         
     | 
| 
       43 
     | 
    
         
            -
                expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
         
     | 
| 
       44 
     | 
    
         
            -
                expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
         
     | 
| 
       45 
     | 
    
         
            -
                expectation_list.add(expectation1)
         
     | 
| 
       46 
     | 
    
         
            -
                expectation_list.add(expectation2)
         
     | 
| 
       47 
     | 
    
         
            -
                assert_same expectation2, expectation_list.match(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
              def test_should_find_matching_expectation_allowing_invocation
         
     | 
| 
       51 
     | 
    
         
            -
                expectation_list = ExpectationList.new
         
     | 
| 
       52 
     | 
    
         
            -
                expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
         
     | 
| 
       53 
     | 
    
         
            -
                expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
         
     | 
| 
       54 
     | 
    
         
            -
                define_instance_method(expectation1, :invocations_allowed?) { true }
         
     | 
| 
       55 
     | 
    
         
            -
                define_instance_method(expectation2, :invocations_allowed?) { true }
         
     | 
| 
       56 
     | 
    
         
            -
                expectation_list.add(expectation1)
         
     | 
| 
       57 
     | 
    
         
            -
                expectation_list.add(expectation2)
         
     | 
| 
       58 
     | 
    
         
            -
                assert_same expectation1, expectation_list.match_allowing_invocation(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
              def test_should_find_most_recent_matching_expectation_allowing_invocation
         
     | 
| 
       62 
     | 
    
         
            -
                expectation_list = ExpectationList.new
         
     | 
| 
       63 
     | 
    
         
            -
                expectation1 = Expectation.new(nil, :my_method)
         
     | 
| 
       64 
     | 
    
         
            -
                expectation2 = Expectation.new(nil, :my_method)
         
     | 
| 
       65 
     | 
    
         
            -
                define_instance_method(expectation1, :invocations_allowed?) { true }
         
     | 
| 
       66 
     | 
    
         
            -
                define_instance_method(expectation2, :invocations_allowed?) { false }
         
     | 
| 
       67 
     | 
    
         
            -
                expectation_list.add(expectation1)
         
     | 
| 
       68 
     | 
    
         
            -
                expectation_list.add(expectation2)
         
     | 
| 
       69 
     | 
    
         
            -
                assert_same expectation1, expectation_list.match_allowing_invocation(Invocation.new(:irrelevant, :my_method))
         
     | 
| 
       70 
     | 
    
         
            -
              end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
              def test_should_combine_two_expectation_lists_into_one
         
     | 
| 
       73 
     | 
    
         
            -
                expectation_list1 = ExpectationList.new
         
     | 
| 
       74 
     | 
    
         
            -
                expectation_list2 = ExpectationList.new
         
     | 
| 
       75 
     | 
    
         
            -
                expectation1 = Expectation.new(nil, :my_method)
         
     | 
| 
       76 
     | 
    
         
            -
                expectation2 = Expectation.new(nil, :my_method)
         
     | 
| 
       77 
     | 
    
         
            -
                expectation_list1.add(expectation1)
         
     | 
| 
       78 
     | 
    
         
            -
                expectation_list2.add(expectation2)
         
     | 
| 
       79 
     | 
    
         
            -
                expectation_list = expectation_list1 + expectation_list2
         
     | 
| 
       80 
     | 
    
         
            -
                assert_equal [expectation1, expectation2], expectation_list.to_a
         
     | 
| 
       81 
     | 
    
         
            -
              end
         
     | 
| 
       82 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,504 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path('../../test_helper', __FILE__)
         
     | 
| 
       2 
     | 
    
         
            -
            require 'mocha/expectation'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'mocha/invocation'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'mocha/sequence'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'mocha/configuration'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'mocha/deprecation'
         
     | 
| 
       7 
     | 
    
         
            -
            require 'execution_point'
         
     | 
| 
       8 
     | 
    
         
            -
            require 'simple_counter'
         
     | 
| 
       9 
     | 
    
         
            -
            require 'deprecation_disabler'
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            # rubocop:disable  Metrics/ClassLength
         
     | 
| 
       12 
     | 
    
         
            -
            class ExpectationTest < Mocha::TestCase
         
     | 
| 
       13 
     | 
    
         
            -
              include Mocha
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              def new_expectation
         
     | 
| 
       16 
     | 
    
         
            -
                Expectation.new(nil, :expected_method)
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              def invoke(expectation, &block)
         
     | 
| 
       20 
     | 
    
         
            -
                expectation.invoke(Invocation.new(:irrelevant, :expected_method, &block))
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              def test_should_match_calls_to_same_method_with_any_parameters
         
     | 
| 
       24 
     | 
    
         
            -
                assert new_expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
         
     | 
| 
       25 
     | 
    
         
            -
              end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              def test_should_match_calls_to_same_method_with_exactly_zero_parameters
         
     | 
| 
       28 
     | 
    
         
            -
                assert new_expectation.with.match?(Invocation.new(:irrelevant, :expected_method))
         
     | 
| 
       29 
     | 
    
         
            -
              end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
         
     | 
| 
       32 
     | 
    
         
            -
                assert !new_expectation.with.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
         
     | 
| 
       33 
     | 
    
         
            -
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
              def test_should_match_calls_to_same_method_with_expected_parameter_values
         
     | 
| 
       36 
     | 
    
         
            -
                assert new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
         
     | 
| 
       37 
     | 
    
         
            -
              end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
              def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
         
     | 
| 
       40 
     | 
    
         
            -
                expectation = new_expectation.with { |x, y, z| x + y == z }
         
     | 
| 
       41 
     | 
    
         
            -
                assert expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
         
     | 
| 
       42 
     | 
    
         
            -
              end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
              def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
         
     | 
| 
       45 
     | 
    
         
            -
                expectation = new_expectation.with { |x, y, z| x + y == z }
         
     | 
| 
       46 
     | 
    
         
            -
                assert !expectation.match?(Invocation.new(:irrelevant, :different_method, 1, 2, 3))
         
     | 
| 
       47 
     | 
    
         
            -
              end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
              def test_should_not_match_calls_to_different_methods_with_no_parameters
         
     | 
| 
       50 
     | 
    
         
            -
                assert !new_expectation.match?(Invocation.new(:irrelevant, :unexpected_method))
         
     | 
| 
       51 
     | 
    
         
            -
              end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
              def test_should_not_match_calls_to_same_method_with_too_few_parameters
         
     | 
| 
       54 
     | 
    
         
            -
                assert !new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 2))
         
     | 
| 
       55 
     | 
    
         
            -
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
              def test_should_not_match_calls_to_same_method_with_too_many_parameters
         
     | 
| 
       58 
     | 
    
         
            -
                assert !new_expectation.with(1, 2).match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
              def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values
         
     | 
| 
       62 
     | 
    
         
            -
                assert !new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 0, 3))
         
     | 
| 
       63 
     | 
    
         
            -
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
              def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
         
     | 
| 
       66 
     | 
    
         
            -
                expectation = new_expectation.with { |x, y, z| x + y == z }
         
     | 
| 
       67 
     | 
    
         
            -
                assert !expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 0, 3))
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
              def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
         
     | 
| 
       71 
     | 
    
         
            -
                expectation = new_expectation.times(1)
         
     | 
| 
       72 
     | 
    
         
            -
                assert expectation.invocations_allowed?
         
     | 
| 
       73 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       74 
     | 
    
         
            -
                assert !expectation.invocations_allowed?
         
     | 
| 
       75 
     | 
    
         
            -
              end
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
              def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
         
     | 
| 
       78 
     | 
    
         
            -
                expectation = new_expectation.times(2)
         
     | 
| 
       79 
     | 
    
         
            -
                2.times do
         
     | 
| 
       80 
     | 
    
         
            -
                  assert expectation.invocations_allowed?
         
     | 
| 
       81 
     | 
    
         
            -
                  invoke(expectation)
         
     | 
| 
       82 
     | 
    
         
            -
                end
         
     | 
| 
       83 
     | 
    
         
            -
                assert !expectation.invocations_allowed?
         
     | 
| 
       84 
     | 
    
         
            -
              end
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
              def test_should_allow_invocations_until_expected_invocation_count_is_a_range_from_two_to_three_and_actual_invocation_count_would_be_four
         
     | 
| 
       87 
     | 
    
         
            -
                expectation = new_expectation.times(2..3)
         
     | 
| 
       88 
     | 
    
         
            -
                3.times do
         
     | 
| 
       89 
     | 
    
         
            -
                  assert expectation.invocations_allowed?
         
     | 
| 
       90 
     | 
    
         
            -
                  invoke(expectation)
         
     | 
| 
       91 
     | 
    
         
            -
                end
         
     | 
| 
       92 
     | 
    
         
            -
                assert !expectation.invocations_allowed?
         
     | 
| 
       93 
     | 
    
         
            -
              end
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
              def test_should_store_provided_backtrace
         
     | 
| 
       96 
     | 
    
         
            -
                backtrace = Object.new
         
     | 
| 
       97 
     | 
    
         
            -
                assert_equal backtrace, Expectation.new(nil, :expected_method, backtrace).backtrace
         
     | 
| 
       98 
     | 
    
         
            -
              end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
              # rubocop:disable Style/Semicolon
         
     | 
| 
       101 
     | 
    
         
            -
              def test_should_default_backtrace_to_caller
         
     | 
| 
       102 
     | 
    
         
            -
                execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
         
     | 
| 
       103 
     | 
    
         
            -
                assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
         
     | 
| 
       104 
     | 
    
         
            -
              end
         
     | 
| 
       105 
     | 
    
         
            -
              # rubocop:enable Style/Semicolon
         
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
              def test_should_not_yield
         
     | 
| 
       108 
     | 
    
         
            -
                yielded = false
         
     | 
| 
       109 
     | 
    
         
            -
                invoke(new_expectation) { yielded = true }
         
     | 
| 
       110 
     | 
    
         
            -
                assert_equal false, yielded
         
     | 
| 
       111 
     | 
    
         
            -
              end
         
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
              def test_should_yield_no_parameters
         
     | 
| 
       114 
     | 
    
         
            -
                yielded_parameters = nil
         
     | 
| 
       115 
     | 
    
         
            -
                invoke(new_expectation.yields) { |*parameters| yielded_parameters = parameters }
         
     | 
| 
       116 
     | 
    
         
            -
                assert_equal [], yielded_parameters
         
     | 
| 
       117 
     | 
    
         
            -
              end
         
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
              def test_yield_should_fail_when_the_caller_does_not_provide_a_block_and_behaviour_from_v1_9_not_retained
         
     | 
| 
       120 
     | 
    
         
            -
                Mocha::Configuration.override(:reinstate_undocumented_behaviour_from_v1_9 => false) do
         
     | 
| 
       121 
     | 
    
         
            -
                  assert_raises(LocalJumpError) { invoke(new_expectation.yields(:foo)) }
         
     | 
| 
       122 
     | 
    
         
            -
                end
         
     | 
| 
       123 
     | 
    
         
            -
              end
         
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
              def test_yields_should_display_warning_when_caller_does_not_provide_block
         
     | 
| 
       126 
     | 
    
         
            -
                DeprecationDisabler.disable_deprecations do
         
     | 
| 
       127 
     | 
    
         
            -
                  invoke(new_expectation.yields(:foo, 1, [2, 3]))
         
     | 
| 
       128 
     | 
    
         
            -
                end
         
     | 
| 
       129 
     | 
    
         
            -
                assert message = Deprecation.messages.last
         
     | 
| 
       130 
     | 
    
         
            -
                assert message.include?('Stubbed method was instructed to yield (:foo, 1, [2, 3])')
         
     | 
| 
       131 
     | 
    
         
            -
                assert message.include?('but no block was given by invocation: :irrelevant.expected_method()')
         
     | 
| 
       132 
     | 
    
         
            -
                assert message.include?('This will raise a LocalJumpError in the future.')
         
     | 
| 
       133 
     | 
    
         
            -
              end
         
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
              def test_multiple_yields_should_display_warning_when_caller_does_not_provide_block
         
     | 
| 
       136 
     | 
    
         
            -
                DeprecationDisabler.disable_deprecations do
         
     | 
| 
       137 
     | 
    
         
            -
                  invoke(new_expectation.multiple_yields(:foo, 1, [2, 3]))
         
     | 
| 
       138 
     | 
    
         
            -
                end
         
     | 
| 
       139 
     | 
    
         
            -
                assert message = Deprecation.messages.last
         
     | 
| 
       140 
     | 
    
         
            -
                assert message.include?('Stubbed method was instructed to yield (2, 3)')
         
     | 
| 
       141 
     | 
    
         
            -
                assert message.include?('but no block was given by invocation: :irrelevant.expected_method()')
         
     | 
| 
       142 
     | 
    
         
            -
                assert message.include?('This will raise a LocalJumpError in the future.')
         
     | 
| 
       143 
     | 
    
         
            -
              end
         
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
              def test_should_yield_with_specified_parameters
         
     | 
| 
       146 
     | 
    
         
            -
                yielded_parameters = nil
         
     | 
| 
       147 
     | 
    
         
            -
                invoke(new_expectation.yields(1, 2, 3)) { |*parameters| yielded_parameters = parameters }
         
     | 
| 
       148 
     | 
    
         
            -
                assert_equal [1, 2, 3], yielded_parameters
         
     | 
| 
       149 
     | 
    
         
            -
              end
         
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
              def test_should_yield_different_parameters_on_consecutive_invocations
         
     | 
| 
       152 
     | 
    
         
            -
                expectation = new_expectation.yields(1, 2, 3).yields(4, 5)
         
     | 
| 
       153 
     | 
    
         
            -
                yielded_parameters = []
         
     | 
| 
       154 
     | 
    
         
            -
                invoke(expectation) { |*parameters| yielded_parameters << parameters }
         
     | 
| 
       155 
     | 
    
         
            -
                invoke(expectation) { |*parameters| yielded_parameters << parameters }
         
     | 
| 
       156 
     | 
    
         
            -
                assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
         
     | 
| 
       157 
     | 
    
         
            -
              end
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
              def test_should_yield_multiple_times_for_single_invocation
         
     | 
| 
       160 
     | 
    
         
            -
                yielded_parameters = []
         
     | 
| 
       161 
     | 
    
         
            -
                invoke(new_expectation.multiple_yields([1, 2, 3], [4, 5])) { |*parameters| yielded_parameters << parameters }
         
     | 
| 
       162 
     | 
    
         
            -
                assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
         
     | 
| 
       163 
     | 
    
         
            -
              end
         
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
              def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation
         
     | 
| 
       166 
     | 
    
         
            -
                expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
         
     | 
| 
       167 
     | 
    
         
            -
                yielded_parameters = []
         
     | 
| 
       168 
     | 
    
         
            -
                invoke(expectation) { |*parameters| yielded_parameters << parameters }
         
     | 
| 
       169 
     | 
    
         
            -
                invoke(expectation) { |*parameters| yielded_parameters << parameters }
         
     | 
| 
       170 
     | 
    
         
            -
                assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters
         
     | 
| 
       171 
     | 
    
         
            -
              end
         
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
              def test_should_return_specified_value
         
     | 
| 
       174 
     | 
    
         
            -
                assert_equal 99, invoke(new_expectation.returns(99))
         
     | 
| 
       175 
     | 
    
         
            -
              end
         
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
              def test_should_return_same_specified_value_multiple_times
         
     | 
| 
       178 
     | 
    
         
            -
                expectation = new_expectation.returns(99)
         
     | 
| 
       179 
     | 
    
         
            -
                assert_equal 99, invoke(expectation)
         
     | 
| 
       180 
     | 
    
         
            -
                assert_equal 99, invoke(expectation)
         
     | 
| 
       181 
     | 
    
         
            -
              end
         
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
              def test_should_return_specified_values_on_consecutive_calls
         
     | 
| 
       184 
     | 
    
         
            -
                expectation = new_expectation.returns(99, 100, 101)
         
     | 
| 
       185 
     | 
    
         
            -
                assert_equal 99, invoke(expectation)
         
     | 
| 
       186 
     | 
    
         
            -
                assert_equal 100, invoke(expectation)
         
     | 
| 
       187 
     | 
    
         
            -
                assert_equal 101, invoke(expectation)
         
     | 
| 
       188 
     | 
    
         
            -
              end
         
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
              def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified
         
     | 
| 
       191 
     | 
    
         
            -
                values = [99, 100, 101]
         
     | 
| 
       192 
     | 
    
         
            -
                expectation = new_expectation.returns(*values)
         
     | 
| 
       193 
     | 
    
         
            -
                values.shift
         
     | 
| 
       194 
     | 
    
         
            -
                assert_equal 99, invoke(expectation)
         
     | 
| 
       195 
     | 
    
         
            -
                assert_equal 100, invoke(expectation)
         
     | 
| 
       196 
     | 
    
         
            -
                assert_equal 101, invoke(expectation)
         
     | 
| 
       197 
     | 
    
         
            -
              end
         
     | 
| 
       198 
     | 
    
         
            -
             
     | 
| 
       199 
     | 
    
         
            -
              def test_should_return_nil_by_default
         
     | 
| 
       200 
     | 
    
         
            -
                assert_nil invoke(new_expectation)
         
     | 
| 
       201 
     | 
    
         
            -
              end
         
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
              def test_should_return_nil_if_no_value_specified
         
     | 
| 
       204 
     | 
    
         
            -
                assert_nil invoke(new_expectation.returns)
         
     | 
| 
       205 
     | 
    
         
            -
              end
         
     | 
| 
       206 
     | 
    
         
            -
             
     | 
| 
       207 
     | 
    
         
            -
              def test_should_raise_runtime_exception
         
     | 
| 
       208 
     | 
    
         
            -
                assert_raises(RuntimeError) { invoke(new_expectation.raises) }
         
     | 
| 
       209 
     | 
    
         
            -
              end
         
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
       211 
     | 
    
         
            -
              def test_should_raise_custom_exception
         
     | 
| 
       212 
     | 
    
         
            -
                exception = Class.new(Exception)
         
     | 
| 
       213 
     | 
    
         
            -
                assert_raises(exception) { invoke(new_expectation.raises(exception)) }
         
     | 
| 
       214 
     | 
    
         
            -
              end
         
     | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
       216 
     | 
    
         
            -
              def test_should_raise_same_instance_of_custom_exception
         
     | 
| 
       217 
     | 
    
         
            -
                exception_klass = Class.new(StandardError)
         
     | 
| 
       218 
     | 
    
         
            -
                expected_exception = exception_klass.new
         
     | 
| 
       219 
     | 
    
         
            -
                actual_exception = assert_raises(exception_klass) { invoke(new_expectation.raises(expected_exception)) }
         
     | 
| 
       220 
     | 
    
         
            -
                assert_same expected_exception, actual_exception
         
     | 
| 
       221 
     | 
    
         
            -
              end
         
     | 
| 
       222 
     | 
    
         
            -
             
     | 
| 
       223 
     | 
    
         
            -
              def test_should_use_the_default_exception_message
         
     | 
| 
       224 
     | 
    
         
            -
                exception = assert_raises(Exception) { invoke(new_expectation.raises(Exception)) }
         
     | 
| 
       225 
     | 
    
         
            -
                assert_equal Exception.new.message, exception.message
         
     | 
| 
       226 
     | 
    
         
            -
              end
         
     | 
| 
       227 
     | 
    
         
            -
             
     | 
| 
       228 
     | 
    
         
            -
              def test_should_raise_custom_exception_with_message
         
     | 
| 
       229 
     | 
    
         
            -
                exception_msg = 'exception message'
         
     | 
| 
       230 
     | 
    
         
            -
                exception = assert_raises(Exception) { invoke(new_expectation.raises(Exception, exception_msg)) }
         
     | 
| 
       231 
     | 
    
         
            -
                assert_equal exception_msg, exception.message
         
     | 
| 
       232 
     | 
    
         
            -
              end
         
     | 
| 
       233 
     | 
    
         
            -
             
     | 
| 
       234 
     | 
    
         
            -
              def test_should_return_values_then_raise_exception
         
     | 
| 
       235 
     | 
    
         
            -
                expectation = new_expectation.returns(1, 2).then.raises
         
     | 
| 
       236 
     | 
    
         
            -
                assert_equal 1, invoke(expectation)
         
     | 
| 
       237 
     | 
    
         
            -
                assert_equal 2, invoke(expectation)
         
     | 
| 
       238 
     | 
    
         
            -
                assert_raises(RuntimeError) { invoke(expectation) }
         
     | 
| 
       239 
     | 
    
         
            -
              end
         
     | 
| 
       240 
     | 
    
         
            -
             
     | 
| 
       241 
     | 
    
         
            -
              def test_should_raise_exception_then_return_values
         
     | 
| 
       242 
     | 
    
         
            -
                expectation = new_expectation.raises.then.returns(1, 2)
         
     | 
| 
       243 
     | 
    
         
            -
                assert_raises(RuntimeError) { invoke(expectation) }
         
     | 
| 
       244 
     | 
    
         
            -
                assert_equal 1, invoke(expectation)
         
     | 
| 
       245 
     | 
    
         
            -
                assert_equal 2, invoke(expectation)
         
     | 
| 
       246 
     | 
    
         
            -
              end
         
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
       248 
     | 
    
         
            -
              def test_should_verify_successfully_if_expected_call_was_made
         
     | 
| 
       249 
     | 
    
         
            -
                expectation = new_expectation
         
     | 
| 
       250 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       251 
     | 
    
         
            -
                assert expectation.verified?
         
     | 
| 
       252 
     | 
    
         
            -
              end
         
     | 
| 
       253 
     | 
    
         
            -
             
     | 
| 
       254 
     | 
    
         
            -
              def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice
         
     | 
| 
       255 
     | 
    
         
            -
                expectation = new_expectation.once
         
     | 
| 
       256 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       257 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       258 
     | 
    
         
            -
                assert !expectation.verified?
         
     | 
| 
       259 
     | 
    
         
            -
              end
         
     | 
| 
       260 
     | 
    
         
            -
             
     | 
| 
       261 
     | 
    
         
            -
              def test_should_not_verify_successfully_if_call_expected_once_but_not_invoked
         
     | 
| 
       262 
     | 
    
         
            -
                assert !new_expectation.once.verified?
         
     | 
| 
       263 
     | 
    
         
            -
              end
         
     | 
| 
       264 
     | 
    
         
            -
             
     | 
| 
       265 
     | 
    
         
            -
              def test_should_verify_successfully_if_call_expected_once_and_invoked_once
         
     | 
| 
       266 
     | 
    
         
            -
                expectation = new_expectation.once
         
     | 
| 
       267 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       268 
     | 
    
         
            -
                assert expectation.verified?
         
     | 
| 
       269 
     | 
    
         
            -
              end
         
     | 
| 
       270 
     | 
    
         
            -
             
     | 
| 
       271 
     | 
    
         
            -
              def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times
         
     | 
| 
       272 
     | 
    
         
            -
                expectation = new_expectation.twice
         
     | 
| 
       273 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       274 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       275 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       276 
     | 
    
         
            -
                assert !expectation.verified?
         
     | 
| 
       277 
     | 
    
         
            -
              end
         
     | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
              def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once
         
     | 
| 
       280 
     | 
    
         
            -
                expectation = new_expectation.twice
         
     | 
| 
       281 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       282 
     | 
    
         
            -
                assert !expectation.verified?
         
     | 
| 
       283 
     | 
    
         
            -
              end
         
     | 
| 
       284 
     | 
    
         
            -
             
     | 
| 
       285 
     | 
    
         
            -
              def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice
         
     | 
| 
       286 
     | 
    
         
            -
                expectation = new_expectation.twice
         
     | 
| 
       287 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       288 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       289 
     | 
    
         
            -
                assert expectation.verified?
         
     | 
| 
       290 
     | 
    
         
            -
              end
         
     | 
| 
       291 
     | 
    
         
            -
             
     | 
| 
       292 
     | 
    
         
            -
              def test_should_verify_successfully_if_expected_call_was_made_at_least_once
         
     | 
| 
       293 
     | 
    
         
            -
                expectation = new_expectation.at_least_once
         
     | 
| 
       294 
     | 
    
         
            -
                3.times { invoke(expectation) }
         
     | 
| 
       295 
     | 
    
         
            -
                assert expectation.verified?
         
     | 
| 
       296 
     | 
    
         
            -
              end
         
     | 
| 
       297 
     | 
    
         
            -
             
     | 
| 
       298 
     | 
    
         
            -
              def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
         
     | 
| 
       299 
     | 
    
         
            -
                expectation = new_expectation.with(1, 2, 3).at_least_once
         
     | 
| 
       300 
     | 
    
         
            -
                assert !expectation.verified?
         
     | 
| 
       301 
     | 
    
         
            -
                assert_match(/expected at least once, invoked never/i, expectation.mocha_inspect)
         
     | 
| 
       302 
     | 
    
         
            -
              end
         
     | 
| 
       303 
     | 
    
         
            -
             
     | 
| 
       304 
     | 
    
         
            -
              def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
         
     | 
| 
       305 
     | 
    
         
            -
                expectation = new_expectation.times(2)
         
     | 
| 
       306 
     | 
    
         
            -
                2.times { invoke(expectation) }
         
     | 
| 
       307 
     | 
    
         
            -
                assert expectation.verified?
         
     | 
| 
       308 
     | 
    
         
            -
              end
         
     | 
| 
       309 
     | 
    
         
            -
             
     | 
| 
       310 
     | 
    
         
            -
              def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
         
     | 
| 
       311 
     | 
    
         
            -
                expectation = new_expectation.times(2)
         
     | 
| 
       312 
     | 
    
         
            -
                1.times { invoke(expectation) }
         
     | 
| 
       313 
     | 
    
         
            -
                assert !expectation.verified?
         
     | 
| 
       314 
     | 
    
         
            -
                assert_match(/expected exactly twice, invoked once/i, expectation.mocha_inspect)
         
     | 
| 
       315 
     | 
    
         
            -
              end
         
     | 
| 
       316 
     | 
    
         
            -
             
     | 
| 
       317 
     | 
    
         
            -
              def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
         
     | 
| 
       318 
     | 
    
         
            -
                expectation = new_expectation.times(2)
         
     | 
| 
       319 
     | 
    
         
            -
                3.times { invoke(expectation) }
         
     | 
| 
       320 
     | 
    
         
            -
                assert !expectation.verified?
         
     | 
| 
       321 
     | 
    
         
            -
              end
         
     | 
| 
       322 
     | 
    
         
            -
             
     | 
| 
       323 
     | 
    
         
            -
              def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng
         
     | 
| 
       324 
     | 
    
         
            -
                expectation = new_expectation
         
     | 
| 
       325 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       326 
     | 
    
         
            -
                assertion_counter = SimpleCounter.new
         
     | 
| 
       327 
     | 
    
         
            -
                expectation.verified?(assertion_counter)
         
     | 
| 
       328 
     | 
    
         
            -
                assert_equal 1, assertion_counter.count
         
     | 
| 
       329 
     | 
    
         
            -
              end
         
     | 
| 
       330 
     | 
    
         
            -
             
     | 
| 
       331 
     | 
    
         
            -
              def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying
         
     | 
| 
       332 
     | 
    
         
            -
                assertion_counter = SimpleCounter.new
         
     | 
| 
       333 
     | 
    
         
            -
                Expectation.new(nil, :expected_method).at_least(0).verified?(assertion_counter)
         
     | 
| 
       334 
     | 
    
         
            -
                assert_equal 0, assertion_counter.count
         
     | 
| 
       335 
     | 
    
         
            -
              end
         
     | 
| 
       336 
     | 
    
         
            -
             
     | 
| 
       337 
     | 
    
         
            -
              # rubocop:disable Style/Semicolon
         
     | 
| 
       338 
     | 
    
         
            -
              def test_should_store_backtrace_from_point_where_expectation_was_created
         
     | 
| 
       339 
     | 
    
         
            -
                execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
         
     | 
| 
       340 
     | 
    
         
            -
                assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
         
     | 
| 
       341 
     | 
    
         
            -
              end
         
     | 
| 
       342 
     | 
    
         
            -
              # rubocop:enable Style/Semicolon
         
     | 
| 
       343 
     | 
    
         
            -
             
     | 
| 
       344 
     | 
    
         
            -
              class FakeMock
         
     | 
| 
       345 
     | 
    
         
            -
                def initialize(name)
         
     | 
| 
       346 
     | 
    
         
            -
                  @name = name
         
     | 
| 
       347 
     | 
    
         
            -
                end
         
     | 
| 
       348 
     | 
    
         
            -
             
     | 
| 
       349 
     | 
    
         
            -
                def mocha_inspect
         
     | 
| 
       350 
     | 
    
         
            -
                  @name
         
     | 
| 
       351 
     | 
    
         
            -
                end
         
     | 
| 
       352 
     | 
    
         
            -
              end
         
     | 
| 
       353 
     | 
    
         
            -
             
     | 
| 
       354 
     | 
    
         
            -
              def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences
         
     | 
| 
       355 
     | 
    
         
            -
                mock = FakeMock.new('mock')
         
     | 
| 
       356 
     | 
    
         
            -
                sequence_one = Sequence.new('one')
         
     | 
| 
       357 
     | 
    
         
            -
                sequence_two = Sequence.new('two')
         
     | 
| 
       358 
     | 
    
         
            -
                expectation = Expectation.new(mock, :expected_method).with(1, 2, { 'a' => true }, { :b => false }, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
         
     | 
| 
       359 
     | 
    
         
            -
                assert !expectation.verified?
         
     | 
| 
       360 
     | 
    
         
            -
                assert_match %{mock.expected_method(1, 2, {"a" => true}, {:b => false}, [1, 2, 3]); in sequence "one"; in sequence "two"}, expectation.mocha_inspect
         
     | 
| 
       361 
     | 
    
         
            -
              end
         
     | 
| 
       362 
     | 
    
         
            -
             
     | 
| 
       363 
     | 
    
         
            -
              class FakeConstraint
         
     | 
| 
       364 
     | 
    
         
            -
                def initialize(allows_invocation_now)
         
     | 
| 
       365 
     | 
    
         
            -
                  @allows_invocation_now = allows_invocation_now
         
     | 
| 
       366 
     | 
    
         
            -
                end
         
     | 
| 
       367 
     | 
    
         
            -
             
     | 
| 
       368 
     | 
    
         
            -
                def allows_invocation_now?
         
     | 
| 
       369 
     | 
    
         
            -
                  @allows_invocation_now
         
     | 
| 
       370 
     | 
    
         
            -
                end
         
     | 
| 
       371 
     | 
    
         
            -
              end
         
     | 
| 
       372 
     | 
    
         
            -
             
     | 
| 
       373 
     | 
    
         
            -
              def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now
         
     | 
| 
       374 
     | 
    
         
            -
                constraint_one = FakeConstraint.new(true)
         
     | 
| 
       375 
     | 
    
         
            -
                constraint_two = FakeConstraint.new(true)
         
     | 
| 
       376 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one)
         
     | 
| 
       377 
     | 
    
         
            -
                expectation.add_ordering_constraint(constraint_one)
         
     | 
| 
       378 
     | 
    
         
            -
                expectation.add_ordering_constraint(constraint_two)
         
     | 
| 
       379 
     | 
    
         
            -
                assert expectation.in_correct_order?
         
     | 
| 
       380 
     | 
    
         
            -
              end
         
     | 
| 
       381 
     | 
    
         
            -
             
     | 
| 
       382 
     | 
    
         
            -
              def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now
         
     | 
| 
       383 
     | 
    
         
            -
                constraint_one = FakeConstraint.new(true)
         
     | 
| 
       384 
     | 
    
         
            -
                constraint_two = FakeConstraint.new(false)
         
     | 
| 
       385 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one)
         
     | 
| 
       386 
     | 
    
         
            -
                expectation.add_ordering_constraint(constraint_one)
         
     | 
| 
       387 
     | 
    
         
            -
                expectation.add_ordering_constraint(constraint_two)
         
     | 
| 
       388 
     | 
    
         
            -
                assert !expectation.in_correct_order?
         
     | 
| 
       389 
     | 
    
         
            -
              end
         
     | 
| 
       390 
     | 
    
         
            -
             
     | 
| 
       391 
     | 
    
         
            -
              def test_should_match_if_all_ordering_constraints_allow_invocation_now
         
     | 
| 
       392 
     | 
    
         
            -
                constraint_one = FakeConstraint.new(true)
         
     | 
| 
       393 
     | 
    
         
            -
                constraint_two = FakeConstraint.new(true)
         
     | 
| 
       394 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one)
         
     | 
| 
       395 
     | 
    
         
            -
                expectation.add_ordering_constraint(constraint_one)
         
     | 
| 
       396 
     | 
    
         
            -
                expectation.add_ordering_constraint(constraint_two)
         
     | 
| 
       397 
     | 
    
         
            -
                assert expectation.match?(Invocation.new(:irrelevant, :method_one))
         
     | 
| 
       398 
     | 
    
         
            -
              end
         
     | 
| 
       399 
     | 
    
         
            -
             
     | 
| 
       400 
     | 
    
         
            -
              def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now
         
     | 
| 
       401 
     | 
    
         
            -
                constraint_one = FakeConstraint.new(true)
         
     | 
| 
       402 
     | 
    
         
            -
                constraint_two = FakeConstraint.new(false)
         
     | 
| 
       403 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one)
         
     | 
| 
       404 
     | 
    
         
            -
                expectation.add_ordering_constraint(constraint_one)
         
     | 
| 
       405 
     | 
    
         
            -
                expectation.add_ordering_constraint(constraint_two)
         
     | 
| 
       406 
     | 
    
         
            -
                assert !expectation.match?(Invocation.new(:irrelevant, :method_one))
         
     | 
| 
       407 
     | 
    
         
            -
              end
         
     | 
| 
       408 
     | 
    
         
            -
             
     | 
| 
       409 
     | 
    
         
            -
              def test_should_not_be_satisfied_when_required_invocation_has_not_been_made
         
     | 
| 
       410 
     | 
    
         
            -
                assert !Expectation.new(nil, :method_one).times(1).satisfied?
         
     | 
| 
       411 
     | 
    
         
            -
              end
         
     | 
| 
       412 
     | 
    
         
            -
             
     | 
| 
       413 
     | 
    
         
            -
              def test_should_be_satisfied_when_required_invocation_has_been_made
         
     | 
| 
       414 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one).times(1)
         
     | 
| 
       415 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       416 
     | 
    
         
            -
                assert expectation.satisfied?
         
     | 
| 
       417 
     | 
    
         
            -
              end
         
     | 
| 
       418 
     | 
    
         
            -
             
     | 
| 
       419 
     | 
    
         
            -
              def test_should_not_be_satisfied_when_minimum_number_of_invocations_has_not_been_made
         
     | 
| 
       420 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one).at_least(2)
         
     | 
| 
       421 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       422 
     | 
    
         
            -
                assert !expectation.satisfied?
         
     | 
| 
       423 
     | 
    
         
            -
              end
         
     | 
| 
       424 
     | 
    
         
            -
             
     | 
| 
       425 
     | 
    
         
            -
              def test_should_be_satisfied_when_minimum_number_of_invocations_has_been_made
         
     | 
| 
       426 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one).at_least(2)
         
     | 
| 
       427 
     | 
    
         
            -
                2.times { invoke(expectation) }
         
     | 
| 
       428 
     | 
    
         
            -
                assert expectation.satisfied?
         
     | 
| 
       429 
     | 
    
         
            -
              end
         
     | 
| 
       430 
     | 
    
         
            -
             
     | 
| 
       431 
     | 
    
         
            -
              class FakeSequence
         
     | 
| 
       432 
     | 
    
         
            -
                attr_reader :expectations
         
     | 
| 
       433 
     | 
    
         
            -
             
     | 
| 
       434 
     | 
    
         
            -
                def initialize
         
     | 
| 
       435 
     | 
    
         
            -
                  @expectations = []
         
     | 
| 
       436 
     | 
    
         
            -
                end
         
     | 
| 
       437 
     | 
    
         
            -
             
     | 
| 
       438 
     | 
    
         
            -
                def constrain_as_next_in_sequence(expectation)
         
     | 
| 
       439 
     | 
    
         
            -
                  @expectations << expectation
         
     | 
| 
       440 
     | 
    
         
            -
                end
         
     | 
| 
       441 
     | 
    
         
            -
              end
         
     | 
| 
       442 
     | 
    
         
            -
             
     | 
| 
       443 
     | 
    
         
            -
              def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence
         
     | 
| 
       444 
     | 
    
         
            -
                sequence_one = FakeSequence.new
         
     | 
| 
       445 
     | 
    
         
            -
                sequence_two = FakeSequence.new
         
     | 
| 
       446 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one)
         
     | 
| 
       447 
     | 
    
         
            -
                assert_equal expectation, expectation.in_sequence(sequence_one, sequence_two)
         
     | 
| 
       448 
     | 
    
         
            -
                assert_equal [expectation], sequence_one.expectations
         
     | 
| 
       449 
     | 
    
         
            -
                assert_equal [expectation], sequence_two.expectations
         
     | 
| 
       450 
     | 
    
         
            -
              end
         
     | 
| 
       451 
     | 
    
         
            -
             
     | 
| 
       452 
     | 
    
         
            -
              class FakeState
         
     | 
| 
       453 
     | 
    
         
            -
                def initialize
         
     | 
| 
       454 
     | 
    
         
            -
                  @active = false
         
     | 
| 
       455 
     | 
    
         
            -
                end
         
     | 
| 
       456 
     | 
    
         
            -
             
     | 
| 
       457 
     | 
    
         
            -
                def activate
         
     | 
| 
       458 
     | 
    
         
            -
                  @active = true
         
     | 
| 
       459 
     | 
    
         
            -
                end
         
     | 
| 
       460 
     | 
    
         
            -
             
     | 
| 
       461 
     | 
    
         
            -
                def active?
         
     | 
| 
       462 
     | 
    
         
            -
                  @active
         
     | 
| 
       463 
     | 
    
         
            -
                end
         
     | 
| 
       464 
     | 
    
         
            -
              end
         
     | 
| 
       465 
     | 
    
         
            -
             
     | 
| 
       466 
     | 
    
         
            -
              def test_should_change_state_when_expectation_is_invoked
         
     | 
| 
       467 
     | 
    
         
            -
                state = FakeState.new
         
     | 
| 
       468 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one)
         
     | 
| 
       469 
     | 
    
         
            -
             
     | 
| 
       470 
     | 
    
         
            -
                expectation.then(state)
         
     | 
| 
       471 
     | 
    
         
            -
             
     | 
| 
       472 
     | 
    
         
            -
                invoke(expectation)
         
     | 
| 
       473 
     | 
    
         
            -
                assert state.active?
         
     | 
| 
       474 
     | 
    
         
            -
              end
         
     | 
| 
       475 
     | 
    
         
            -
             
     | 
| 
       476 
     | 
    
         
            -
              def test_should_match_when_state_is_active
         
     | 
| 
       477 
     | 
    
         
            -
                state = FakeState.new
         
     | 
| 
       478 
     | 
    
         
            -
                expectation = Expectation.new(nil, :method_one)
         
     | 
| 
       479 
     | 
    
         
            -
             
     | 
| 
       480 
     | 
    
         
            -
                expectation.when(state)
         
     | 
| 
       481 
     | 
    
         
            -
                assert !expectation.match?(Invocation.new(:irrelevant, :method_one))
         
     | 
| 
       482 
     | 
    
         
            -
             
     | 
| 
       483 
     | 
    
         
            -
                state.activate
         
     | 
| 
       484 
     | 
    
         
            -
                assert expectation.match?(Invocation.new(:irrelevant, :method_one))
         
     | 
| 
       485 
     | 
    
         
            -
              end
         
     | 
| 
       486 
     | 
    
         
            -
             
     | 
| 
       487 
     | 
    
         
            -
              def test_should_include_default_representation_of_object_in_inspect
         
     | 
| 
       488 
     | 
    
         
            -
                object = Object.new
         
     | 
| 
       489 
     | 
    
         
            -
                class << object
         
     | 
| 
       490 
     | 
    
         
            -
                  define_method(:inspect) { 'mock' }
         
     | 
| 
       491 
     | 
    
         
            -
                end
         
     | 
| 
       492 
     | 
    
         
            -
                assert_match Regexp.new('^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$'), Expectation.new(object, :method_one).inspect
         
     | 
| 
       493 
     | 
    
         
            -
              end
         
     | 
| 
       494 
     | 
    
         
            -
             
     | 
| 
       495 
     | 
    
         
            -
              def test_should_include_output_of_mocha_inspect_in_inspect
         
     | 
| 
       496 
     | 
    
         
            -
                object = Object.new
         
     | 
| 
       497 
     | 
    
         
            -
                class << object
         
     | 
| 
       498 
     | 
    
         
            -
                  define_method(:inspect) { 'mock' }
         
     | 
| 
       499 
     | 
    
         
            -
                end
         
     | 
| 
       500 
     | 
    
         
            -
                expectation = Expectation.new(object, :method_one)
         
     | 
| 
       501 
     | 
    
         
            -
                assert expectation.inspect.include?(expectation.mocha_inspect)
         
     | 
| 
       502 
     | 
    
         
            -
              end
         
     | 
| 
       503 
     | 
    
         
            -
            end
         
     | 
| 
       504 
     | 
    
         
            -
            # rubocop:enable  Metrics/ClassLength
         
     |