newbamboo-rspec 1.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +4 -0
- data/History.txt +1263 -0
- data/License.txt +22 -0
- data/Manifest.txt +327 -0
- data/README.txt +57 -0
- data/Rakefile +104 -0
- data/TODO.txt +18 -0
- data/bin/autospec +4 -0
- data/bin/spec +4 -0
- data/examples/failing/README.txt +7 -0
- data/examples/failing/diffing_spec.rb +36 -0
- data/examples/failing/failing_autogenerated_docstrings_example.rb +19 -0
- data/examples/failing/failure_in_after.rb +10 -0
- data/examples/failing/failure_in_before.rb +10 -0
- data/examples/failing/mocking_example.rb +40 -0
- data/examples/failing/mocking_with_flexmock.rb +26 -0
- data/examples/failing/mocking_with_mocha.rb +25 -0
- data/examples/failing/mocking_with_rr.rb +27 -0
- data/examples/failing/partial_mock_example.rb +20 -0
- data/examples/failing/predicate_example.rb +34 -0
- data/examples/failing/raising_example.rb +47 -0
- data/examples/failing/spec_helper.rb +3 -0
- data/examples/failing/syntax_error_example.rb +7 -0
- data/examples/failing/team_spec.rb +44 -0
- data/examples/failing/timeout_behaviour.rb +7 -0
- data/examples/passing/autogenerated_docstrings_example.rb +25 -0
- data/examples/passing/before_and_after_example.rb +40 -0
- data/examples/passing/behave_as_example.rb +45 -0
- data/examples/passing/custom_expectation_matchers.rb +54 -0
- data/examples/passing/custom_formatter.rb +12 -0
- data/examples/passing/dynamic_spec.rb +9 -0
- data/examples/passing/file_accessor.rb +19 -0
- data/examples/passing/file_accessor_spec.rb +38 -0
- data/examples/passing/greeter_spec.rb +31 -0
- data/examples/passing/helper_method_example.rb +14 -0
- data/examples/passing/io_processor.rb +8 -0
- data/examples/passing/io_processor_spec.rb +21 -0
- data/examples/passing/legacy_spec.rb +11 -0
- data/examples/passing/mocking_example.rb +27 -0
- data/examples/passing/multi_threaded_example_group_runner.rb +26 -0
- data/examples/passing/nested_classes_example.rb +36 -0
- data/examples/passing/partial_mock_example.rb +29 -0
- data/examples/passing/pending_example.rb +20 -0
- data/examples/passing/predicate_example.rb +27 -0
- data/examples/passing/priority.txt +1 -0
- data/examples/passing/shared_example_group_example.rb +81 -0
- data/examples/passing/shared_stack_examples.rb +36 -0
- data/examples/passing/simple_matcher_example.rb +31 -0
- data/examples/passing/spec_helper.rb +3 -0
- data/examples/passing/stack.rb +36 -0
- data/examples/passing/stack_spec.rb +64 -0
- data/examples/passing/stack_spec_with_nested_example_groups.rb +67 -0
- data/examples/passing/stubbing_example.rb +69 -0
- data/examples/passing/yielding_example.rb +33 -0
- data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +86 -0
- data/features/before_and_after_blocks/before_and_after_blocks.feature +168 -0
- data/features/example_groups/autogenerated_docstrings.feature +45 -0
- data/features/example_groups/example_group_with_should_methods.feature +17 -0
- data/features/example_groups/nested_groups.feature +17 -0
- data/features/example_groups/output.feature +20 -0
- data/features/interop/examples_and_tests_together.feature +31 -0
- data/features/interop/test_but_not_test_unit.feature +14 -0
- data/features/interop/test_case_with_should_methods.feature +17 -0
- data/features/mock_framework_integration/use_flexmock.feature +27 -0
- data/features/step_definitions/running_rspec.rb +54 -0
- data/features/support/env.rb +26 -0
- data/features/support/helpers/cmdline.rb +9 -0
- data/features/support/matchers/smart_match.rb +37 -0
- data/init.rb +9 -0
- data/lib/adapters/mock_frameworks/flexmock.rb +24 -0
- data/lib/adapters/mock_frameworks/mocha.rb +20 -0
- data/lib/adapters/mock_frameworks/rr.rb +22 -0
- data/lib/adapters/mock_frameworks/rspec.rb +20 -0
- data/lib/autotest/discover.rb +3 -0
- data/lib/autotest/rspec.rb +47 -0
- data/lib/spec/dsl/main.rb +87 -0
- data/lib/spec/dsl.rb +1 -0
- data/lib/spec/example/before_and_after_hooks.rb +99 -0
- data/lib/spec/example/errors.rb +30 -0
- data/lib/spec/example/example_group.rb +26 -0
- data/lib/spec/example/example_group_factory.rb +98 -0
- data/lib/spec/example/example_group_methods.rb +376 -0
- data/lib/spec/example/example_matcher.rb +44 -0
- data/lib/spec/example/example_methods.rb +137 -0
- data/lib/spec/example/module_reopening_fix.rb +21 -0
- data/lib/spec/example/pending.rb +18 -0
- data/lib/spec/example/shared_example_group.rb +59 -0
- data/lib/spec/example.rb +187 -0
- data/lib/spec/expectations/differs/default.rb +66 -0
- data/lib/spec/expectations/errors.rb +12 -0
- data/lib/spec/expectations/extensions/object.rb +63 -0
- data/lib/spec/expectations/extensions/string_and_symbol.rb +17 -0
- data/lib/spec/expectations/extensions.rb +2 -0
- data/lib/spec/expectations/handler.rb +32 -0
- data/lib/spec/expectations.rb +60 -0
- data/lib/spec/interop/test/unit/autorunner.rb +6 -0
- data/lib/spec/interop/test/unit/testcase.rb +73 -0
- data/lib/spec/interop/test/unit/testresult.rb +6 -0
- data/lib/spec/interop/test/unit/testsuite_adapter.rb +34 -0
- data/lib/spec/interop/test/unit/ui/console/testrunner.rb +61 -0
- data/lib/spec/interop/test.rb +12 -0
- data/lib/spec/matchers/be.rb +208 -0
- data/lib/spec/matchers/be_close.rb +21 -0
- data/lib/spec/matchers/change.rb +148 -0
- data/lib/spec/matchers/eql.rb +25 -0
- data/lib/spec/matchers/equal.rb +25 -0
- data/lib/spec/matchers/errors.rb +5 -0
- data/lib/spec/matchers/exist.rb +16 -0
- data/lib/spec/matchers/generated_descriptions.rb +48 -0
- data/lib/spec/matchers/has.rb +15 -0
- data/lib/spec/matchers/have.rb +150 -0
- data/lib/spec/matchers/include.rb +80 -0
- data/lib/spec/matchers/match.rb +22 -0
- data/lib/spec/matchers/match_array.rb +79 -0
- data/lib/spec/matchers/method_missing.rb +9 -0
- data/lib/spec/matchers/operator_matcher.rb +70 -0
- data/lib/spec/matchers/raise_error.rb +128 -0
- data/lib/spec/matchers/respond_to.rb +71 -0
- data/lib/spec/matchers/satisfy.rb +47 -0
- data/lib/spec/matchers/simple_matcher.rb +132 -0
- data/lib/spec/matchers/throw_symbol.rb +106 -0
- data/lib/spec/matchers/wrap_expectation.rb +55 -0
- data/lib/spec/matchers.rb +141 -0
- data/lib/spec/mocks/argument_expectation.rb +49 -0
- data/lib/spec/mocks/argument_matchers.rb +237 -0
- data/lib/spec/mocks/error_generator.rb +82 -0
- data/lib/spec/mocks/errors.rb +10 -0
- data/lib/spec/mocks/extensions/object.rb +3 -0
- data/lib/spec/mocks/extensions.rb +1 -0
- data/lib/spec/mocks/framework.rb +15 -0
- data/lib/spec/mocks/message_expectation.rb +331 -0
- data/lib/spec/mocks/methods.rb +51 -0
- data/lib/spec/mocks/mock.rb +55 -0
- data/lib/spec/mocks/order_group.rb +29 -0
- data/lib/spec/mocks/proxy.rb +230 -0
- data/lib/spec/mocks/space.rb +28 -0
- data/lib/spec/mocks/spec_methods.rb +55 -0
- data/lib/spec/mocks.rb +200 -0
- data/lib/spec/rake/spectask.rb +225 -0
- data/lib/spec/rake/verify_rcov.rb +52 -0
- data/lib/spec/ruby.rb +9 -0
- data/lib/spec/runner/backtrace_tweaker.rb +58 -0
- data/lib/spec/runner/class_and_arguments_parser.rb +14 -0
- data/lib/spec/runner/command_line.rb +35 -0
- data/lib/spec/runner/configuration.rb +166 -0
- data/lib/spec/runner/drb_command_line.rb +20 -0
- data/lib/spec/runner/example_group_runner.rb +70 -0
- data/lib/spec/runner/formatter/base_formatter.rb +79 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +127 -0
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +27 -0
- data/lib/spec/runner/formatter/failing_examples_formatter.rb +20 -0
- data/lib/spec/runner/formatter/html_formatter.rb +340 -0
- data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
- data/lib/spec/runner/formatter/profile_formatter.rb +51 -0
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +34 -0
- data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +39 -0
- data/lib/spec/runner/formatter/text_mate_formatter.rb +16 -0
- data/lib/spec/runner/heckle_runner.rb +74 -0
- data/lib/spec/runner/heckle_runner_unsupported.rb +10 -0
- data/lib/spec/runner/option_parser.rb +204 -0
- data/lib/spec/runner/options.rb +320 -0
- data/lib/spec/runner/reporter.rb +167 -0
- data/lib/spec/runner/spec_parser.rb +73 -0
- data/lib/spec/runner.rb +88 -0
- data/lib/spec/version.rb +15 -0
- data/lib/spec.rb +7 -0
- data/resources/rake/examples.rake +7 -0
- data/resources/rake/examples_with_rcov.rake +9 -0
- data/resources/rake/failing_examples_with_html.rake +9 -0
- data/resources/rake/verify_rcov.rake +7 -0
- data/resources/spec/example_group_with_should_methods.rb +12 -0
- data/resources/spec/simple_spec.rb +8 -0
- data/resources/test/spec_and_test_together.rb +57 -0
- data/resources/test/spec_including_test_but_not_unit.rb +11 -0
- data/resources/test/test_case_with_should_methods.rb +30 -0
- data/rspec.gemspec +32 -0
- data/spec/README.jruby +15 -0
- data/spec/autotest/autotest_helper.rb +6 -0
- data/spec/autotest/autotest_matchers.rb +47 -0
- data/spec/autotest/discover_spec.rb +8 -0
- data/spec/autotest/failed_results_re_spec.rb +24 -0
- data/spec/autotest/rspec_spec.rb +114 -0
- data/spec/rspec_suite.rb +6 -0
- data/spec/ruby_forker.rb +13 -0
- data/spec/spec/dsl/main_spec.rb +88 -0
- data/spec/spec/example/example_group_class_definition_spec.rb +49 -0
- data/spec/spec/example/example_group_factory_spec.rb +224 -0
- data/spec/spec/example/example_group_methods_spec.rb +653 -0
- data/spec/spec/example/example_group_spec.rb +661 -0
- data/spec/spec/example/example_matcher_spec.rb +79 -0
- data/spec/spec/example/example_methods_spec.rb +204 -0
- data/spec/spec/example/helper_method_spec.rb +24 -0
- data/spec/spec/example/nested_example_group_spec.rb +71 -0
- data/spec/spec/example/pending_module_spec.rb +139 -0
- data/spec/spec/example/predicate_matcher_spec.rb +21 -0
- data/spec/spec/example/shared_example_group_spec.rb +257 -0
- data/spec/spec/example/subclassing_example_group_spec.rb +25 -0
- data/spec/spec/expectations/differs/default_spec.rb +127 -0
- data/spec/spec/expectations/extensions/object_spec.rb +45 -0
- data/spec/spec/expectations/fail_with_spec.rb +71 -0
- data/spec/spec/expectations/wrap_expectation_spec.rb +30 -0
- data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +10 -0
- data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +10 -0
- data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +10 -0
- data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
- data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +10 -0
- data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +10 -0
- data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +10 -0
- data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +38 -0
- data/spec/spec/interop/test/unit/spec_spec.rb +48 -0
- data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +18 -0
- data/spec/spec/interop/test/unit/testcase_spec.rb +49 -0
- data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +9 -0
- data/spec/spec/matchers/be_close_spec.rb +41 -0
- data/spec/spec/matchers/be_spec.rb +303 -0
- data/spec/spec/matchers/change_spec.rb +329 -0
- data/spec/spec/matchers/description_generation_spec.rb +172 -0
- data/spec/spec/matchers/eql_spec.rb +29 -0
- data/spec/spec/matchers/equal_spec.rb +29 -0
- data/spec/spec/matchers/exist_spec.rb +57 -0
- data/spec/spec/matchers/handler_spec.rb +111 -0
- data/spec/spec/matchers/has_spec.rb +63 -0
- data/spec/spec/matchers/have_spec.rb +399 -0
- data/spec/spec/matchers/include_spec.rb +88 -0
- data/spec/spec/matchers/match_array_spec.rb +83 -0
- data/spec/spec/matchers/match_spec.rb +37 -0
- data/spec/spec/matchers/matcher_methods_spec.rb +66 -0
- data/spec/spec/matchers/operator_matcher_spec.rb +191 -0
- data/spec/spec/matchers/raise_error_spec.rb +333 -0
- data/spec/spec/matchers/respond_to_spec.rb +116 -0
- data/spec/spec/matchers/satisfy_spec.rb +36 -0
- data/spec/spec/matchers/simple_matcher_spec.rb +93 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +96 -0
- data/spec/spec/mocks/any_number_of_times_spec.rb +36 -0
- data/spec/spec/mocks/argument_expectation_spec.rb +23 -0
- data/spec/spec/mocks/at_least_spec.rb +97 -0
- data/spec/spec/mocks/at_most_spec.rb +93 -0
- data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
- data/spec/spec/mocks/bug_report_10263_spec.rb +24 -0
- data/spec/spec/mocks/bug_report_11545_spec.rb +32 -0
- data/spec/spec/mocks/bug_report_15719_spec.rb +30 -0
- data/spec/spec/mocks/bug_report_496.rb +19 -0
- data/spec/spec/mocks/bug_report_600_spec.rb +22 -0
- data/spec/spec/mocks/bug_report_7611_spec.rb +19 -0
- data/spec/spec/mocks/bug_report_7805_spec.rb +22 -0
- data/spec/spec/mocks/bug_report_8165_spec.rb +31 -0
- data/spec/spec/mocks/bug_report_8302_spec.rb +26 -0
- data/spec/spec/mocks/failing_argument_matchers_spec.rb +95 -0
- data/spec/spec/mocks/hash_including_matcher_spec.rb +90 -0
- data/spec/spec/mocks/hash_not_including_matcher_spec.rb +67 -0
- data/spec/spec/mocks/mock_ordering_spec.rb +84 -0
- data/spec/spec/mocks/mock_space_spec.rb +54 -0
- data/spec/spec/mocks/mock_spec.rb +579 -0
- data/spec/spec/mocks/multiple_return_value_spec.rb +113 -0
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +53 -0
- data/spec/spec/mocks/null_object_mock_spec.rb +54 -0
- data/spec/spec/mocks/once_counts_spec.rb +53 -0
- data/spec/spec/mocks/options_hash_spec.rb +35 -0
- data/spec/spec/mocks/partial_mock_spec.rb +149 -0
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +66 -0
- data/spec/spec/mocks/passing_argument_matchers_spec.rb +145 -0
- data/spec/spec/mocks/precise_counts_spec.rb +52 -0
- data/spec/spec/mocks/record_messages_spec.rb +26 -0
- data/spec/spec/mocks/stub_spec.rb +194 -0
- data/spec/spec/mocks/stubbed_message_expectations_spec.rb +14 -0
- data/spec/spec/mocks/twice_counts_spec.rb +67 -0
- data/spec/spec/package/bin_spec_spec.rb +22 -0
- data/spec/spec/runner/class_and_argument_parser_spec.rb +23 -0
- data/spec/spec/runner/command_line_spec.rb +141 -0
- data/spec/spec/runner/configuration_spec.rb +301 -0
- data/spec/spec/runner/drb_command_line_spec.rb +97 -0
- data/spec/spec/runner/empty_file.txt +0 -0
- data/spec/spec/runner/example_group_runner_spec.rb +33 -0
- data/spec/spec/runner/examples.txt +2 -0
- data/spec/spec/runner/failed.txt +3 -0
- data/spec/spec/runner/formatter/base_formatter_spec.rb +23 -0
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +23 -0
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +45 -0
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +33 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.4.html +365 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +387 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.5.html +371 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +381 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +379 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.7.html +379 -0
- data/spec/spec/runner/formatter/html_formatted-1.9.1.html +379 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +62 -0
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +318 -0
- data/spec/spec/runner/formatter/profile_formatter_spec.rb +65 -0
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +145 -0
- data/spec/spec/runner/formatter/snippet_extractor_spec.rb +18 -0
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +104 -0
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +159 -0
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +365 -0
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +373 -0
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +373 -0
- data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +373 -0
- data/spec/spec/runner/heckle_runner_spec.rb +78 -0
- data/spec/spec/runner/heckler_spec.rb +20 -0
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +45 -0
- data/spec/spec/runner/option_parser_spec.rb +396 -0
- data/spec/spec/runner/options_spec.rb +469 -0
- data/spec/spec/runner/output_one_time_fixture.rb +7 -0
- data/spec/spec/runner/output_one_time_fixture_runner.rb +8 -0
- data/spec/spec/runner/output_one_time_spec.rb +16 -0
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +62 -0
- data/spec/spec/runner/reporter_spec.rb +238 -0
- data/spec/spec/runner/resources/a_bar.rb +0 -0
- data/spec/spec/runner/resources/a_foo.rb +0 -0
- data/spec/spec/runner/resources/a_spec.rb +1 -0
- data/spec/spec/runner/resources/custom_example_group_runner.rb +14 -0
- data/spec/spec/runner/resources/utf8_encoded.rb +7 -0
- data/spec/spec/runner/spec.opts +2 -0
- data/spec/spec/runner/spec_drb.opts +1 -0
- data/spec/spec/runner/spec_parser/spec_parser_fixture.rb +70 -0
- data/spec/spec/runner/spec_parser_spec.rb +91 -0
- data/spec/spec/runner/spec_spaced.opts +2 -0
- data/spec/spec/runner_spec.rb +11 -0
- data/spec/spec/spec_classes.rb +133 -0
- data/spec/spec/spec_spec.rb +21 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +107 -0
- metadata +388 -0
@@ -0,0 +1,331 @@
|
|
1
|
+
module Spec
|
2
|
+
module Mocks
|
3
|
+
|
4
|
+
class BaseExpectation
|
5
|
+
attr_reader :sym
|
6
|
+
attr_writer :expected_received_count, :method_block, :expected_from
|
7
|
+
protected :expected_received_count=, :method_block=, :expected_from=
|
8
|
+
attr_accessor :error_generator
|
9
|
+
protected :error_generator, :error_generator=
|
10
|
+
|
11
|
+
def initialize(error_generator, expectation_ordering, expected_from, sym, method_block, expected_received_count=1, opts={})
|
12
|
+
@error_generator = error_generator
|
13
|
+
@error_generator.opts = opts
|
14
|
+
@expected_from = expected_from
|
15
|
+
@sym = sym
|
16
|
+
@method_block = method_block
|
17
|
+
@return_block = nil
|
18
|
+
@actual_received_count = 0
|
19
|
+
@expected_received_count = expected_received_count
|
20
|
+
@args_expectation = ArgumentExpectation.new([ArgumentMatchers::AnyArgsMatcher.new])
|
21
|
+
@consecutive = false
|
22
|
+
@exception_to_raise = nil
|
23
|
+
@symbol_to_throw = nil
|
24
|
+
@order_group = expectation_ordering
|
25
|
+
@at_least = nil
|
26
|
+
@at_most = nil
|
27
|
+
@args_to_yield = []
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_child(expected_from, method_block, expected_received_count, opts={})
|
31
|
+
child = clone
|
32
|
+
child.expected_from = expected_from
|
33
|
+
child.method_block = method_block
|
34
|
+
child.expected_received_count = expected_received_count
|
35
|
+
child.clear_actual_received_count!
|
36
|
+
new_gen = error_generator.clone
|
37
|
+
new_gen.opts = opts
|
38
|
+
child.error_generator = new_gen
|
39
|
+
child.clone_args_to_yield @args_to_yield
|
40
|
+
child
|
41
|
+
end
|
42
|
+
|
43
|
+
def expected_args
|
44
|
+
@args_expectation.args
|
45
|
+
end
|
46
|
+
|
47
|
+
def and_return(*values, &return_block)
|
48
|
+
Kernel::raise AmbiguousReturnError unless @method_block.nil?
|
49
|
+
case values.size
|
50
|
+
when 0 then value = nil
|
51
|
+
when 1 then value = values[0]
|
52
|
+
else
|
53
|
+
value = values
|
54
|
+
@consecutive = true
|
55
|
+
@expected_received_count = values.size if !ignoring_args? &&
|
56
|
+
@expected_received_count < values.size
|
57
|
+
end
|
58
|
+
@return_block = block_given? ? return_block : lambda { value }
|
59
|
+
# Ruby 1.9 - see where this is used below
|
60
|
+
@ignore_args = !block_given?
|
61
|
+
end
|
62
|
+
|
63
|
+
# :call-seq:
|
64
|
+
# and_raise()
|
65
|
+
# and_raise(Exception) #any exception class
|
66
|
+
# and_raise(exception) #any exception object
|
67
|
+
#
|
68
|
+
# == Warning
|
69
|
+
#
|
70
|
+
# When you pass an exception class, the MessageExpectation will
|
71
|
+
# raise an instance of it, creating it with +new+. If the exception
|
72
|
+
# class initializer requires any parameters, you must pass in an
|
73
|
+
# instance and not the class.
|
74
|
+
def and_raise(exception=Exception)
|
75
|
+
@exception_to_raise = exception
|
76
|
+
end
|
77
|
+
|
78
|
+
def and_throw(symbol)
|
79
|
+
@symbol_to_throw = symbol
|
80
|
+
end
|
81
|
+
|
82
|
+
def and_yield(*args)
|
83
|
+
if @args_to_yield_were_cloned
|
84
|
+
@args_to_yield.clear
|
85
|
+
@args_to_yield_were_cloned = false
|
86
|
+
end
|
87
|
+
|
88
|
+
@args_to_yield << args
|
89
|
+
self
|
90
|
+
end
|
91
|
+
|
92
|
+
def matches(sym, args)
|
93
|
+
@sym == sym and @args_expectation.args_match?(args)
|
94
|
+
end
|
95
|
+
|
96
|
+
def invoke(args, block)
|
97
|
+
if @expected_received_count == 0
|
98
|
+
@failed_fast = true
|
99
|
+
@actual_received_count += 1
|
100
|
+
@error_generator.raise_expectation_error @sym, @expected_received_count, @actual_received_count, *args
|
101
|
+
end
|
102
|
+
|
103
|
+
@order_group.handle_order_constraint self
|
104
|
+
|
105
|
+
begin
|
106
|
+
Kernel::raise @exception_to_raise unless @exception_to_raise.nil?
|
107
|
+
Kernel::throw @symbol_to_throw unless @symbol_to_throw.nil?
|
108
|
+
|
109
|
+
|
110
|
+
if !@method_block.nil?
|
111
|
+
default_return_val = invoke_method_block(args)
|
112
|
+
elsif @args_to_yield.size > 0
|
113
|
+
default_return_val = invoke_with_yield(block)
|
114
|
+
else
|
115
|
+
default_return_val = nil
|
116
|
+
end
|
117
|
+
|
118
|
+
if @consecutive
|
119
|
+
return invoke_consecutive_return_block(args, block)
|
120
|
+
elsif @return_block
|
121
|
+
return invoke_return_block(args, block)
|
122
|
+
else
|
123
|
+
return default_return_val
|
124
|
+
end
|
125
|
+
ensure
|
126
|
+
@actual_received_count += 1
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def called_max_times?
|
131
|
+
@expected_received_count != :any && @expected_received_count > 0 &&
|
132
|
+
@actual_received_count >= @expected_received_count
|
133
|
+
end
|
134
|
+
|
135
|
+
protected
|
136
|
+
|
137
|
+
def invoke_method_block(args)
|
138
|
+
begin
|
139
|
+
@method_block.call(*args)
|
140
|
+
rescue => detail
|
141
|
+
@error_generator.raise_block_failed_error @sym, detail.message
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def invoke_with_yield(block)
|
146
|
+
if block.nil?
|
147
|
+
@error_generator.raise_missing_block_error @args_to_yield
|
148
|
+
end
|
149
|
+
value = nil
|
150
|
+
@args_to_yield.each do |args_to_yield_this_time|
|
151
|
+
if block.arity > -1 && args_to_yield_this_time.length != block.arity
|
152
|
+
@error_generator.raise_wrong_arity_error args_to_yield_this_time, block.arity
|
153
|
+
end
|
154
|
+
value = block.call(*args_to_yield_this_time)
|
155
|
+
end
|
156
|
+
value
|
157
|
+
end
|
158
|
+
|
159
|
+
def invoke_consecutive_return_block(args, block)
|
160
|
+
args << block unless block.nil?
|
161
|
+
value = @return_block.call(*args)
|
162
|
+
|
163
|
+
index = [@actual_received_count, value.size-1].min
|
164
|
+
value[index]
|
165
|
+
end
|
166
|
+
|
167
|
+
def invoke_return_block(args, block)
|
168
|
+
args << block unless block.nil?
|
169
|
+
# Ruby 1.9 - when we set @return_block to return values
|
170
|
+
# regardless of arguments, any arguments will result in
|
171
|
+
# a "wrong number of arguments" error
|
172
|
+
if @ignore_args
|
173
|
+
@return_block.call()
|
174
|
+
else
|
175
|
+
@return_block.call(*args)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def clone_args_to_yield(args)
|
180
|
+
@args_to_yield = args.clone
|
181
|
+
@args_to_yield_were_cloned = true
|
182
|
+
end
|
183
|
+
|
184
|
+
def failed_fast?
|
185
|
+
@failed_fast
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
class MessageExpectation < BaseExpectation
|
190
|
+
|
191
|
+
def matches_name_but_not_args(sym, args)
|
192
|
+
@sym == sym and not @args_expectation.args_match?(args)
|
193
|
+
end
|
194
|
+
|
195
|
+
def verify_messages_received
|
196
|
+
return if expected_messages_received? || failed_fast?
|
197
|
+
|
198
|
+
generate_error
|
199
|
+
rescue Spec::Mocks::MockExpectationError => error
|
200
|
+
error.backtrace.insert(0, @expected_from)
|
201
|
+
Kernel::raise error
|
202
|
+
end
|
203
|
+
|
204
|
+
def expected_messages_received?
|
205
|
+
ignoring_args? || matches_exact_count? ||
|
206
|
+
matches_at_least_count? || matches_at_most_count?
|
207
|
+
end
|
208
|
+
|
209
|
+
def ignoring_args?
|
210
|
+
@expected_received_count == :any
|
211
|
+
end
|
212
|
+
|
213
|
+
def matches_at_least_count?
|
214
|
+
@at_least && @actual_received_count >= @expected_received_count
|
215
|
+
end
|
216
|
+
|
217
|
+
def matches_at_most_count?
|
218
|
+
@at_most && @actual_received_count <= @expected_received_count
|
219
|
+
end
|
220
|
+
|
221
|
+
def matches_exact_count?
|
222
|
+
@expected_received_count == @actual_received_count
|
223
|
+
end
|
224
|
+
|
225
|
+
def similar_messages
|
226
|
+
@similar_messages ||= []
|
227
|
+
end
|
228
|
+
|
229
|
+
def advise(args, block)
|
230
|
+
similar_messages << args
|
231
|
+
end
|
232
|
+
|
233
|
+
def generate_error
|
234
|
+
if similar_messages.empty?
|
235
|
+
@error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
|
236
|
+
else
|
237
|
+
@error_generator.raise_unexpected_message_args_error(self, *@similar_messages.first)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def with(*args, &block)
|
242
|
+
@args_expectation = ArgumentExpectation.new(args, &block)
|
243
|
+
self
|
244
|
+
end
|
245
|
+
|
246
|
+
def exactly(n)
|
247
|
+
set_expected_received_count :exactly, n
|
248
|
+
self
|
249
|
+
end
|
250
|
+
|
251
|
+
def at_least(n)
|
252
|
+
set_expected_received_count :at_least, n
|
253
|
+
self
|
254
|
+
end
|
255
|
+
|
256
|
+
def at_most(n)
|
257
|
+
set_expected_received_count :at_most, n
|
258
|
+
self
|
259
|
+
end
|
260
|
+
|
261
|
+
def times(&block)
|
262
|
+
@method_block = block if block
|
263
|
+
self
|
264
|
+
end
|
265
|
+
|
266
|
+
def any_number_of_times(&block)
|
267
|
+
@method_block = block if block
|
268
|
+
@expected_received_count = :any
|
269
|
+
self
|
270
|
+
end
|
271
|
+
|
272
|
+
def never
|
273
|
+
@expected_received_count = 0
|
274
|
+
self
|
275
|
+
end
|
276
|
+
|
277
|
+
def once(&block)
|
278
|
+
@method_block = block if block
|
279
|
+
@expected_received_count = 1
|
280
|
+
self
|
281
|
+
end
|
282
|
+
|
283
|
+
def twice(&block)
|
284
|
+
@method_block = block if block
|
285
|
+
@expected_received_count = 2
|
286
|
+
self
|
287
|
+
end
|
288
|
+
|
289
|
+
def ordered(&block)
|
290
|
+
@method_block = block if block
|
291
|
+
@order_group.register(self)
|
292
|
+
@ordered = true
|
293
|
+
self
|
294
|
+
end
|
295
|
+
|
296
|
+
def negative_expectation_for?(sym)
|
297
|
+
return false
|
298
|
+
end
|
299
|
+
|
300
|
+
protected
|
301
|
+
def set_expected_received_count(relativity, n)
|
302
|
+
@at_least = (relativity == :at_least)
|
303
|
+
@at_most = (relativity == :at_most)
|
304
|
+
@expected_received_count = case n
|
305
|
+
when Numeric
|
306
|
+
n
|
307
|
+
when :once
|
308
|
+
1
|
309
|
+
when :twice
|
310
|
+
2
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def clear_actual_received_count!
|
315
|
+
@actual_received_count = 0
|
316
|
+
end
|
317
|
+
|
318
|
+
end
|
319
|
+
|
320
|
+
class NegativeMessageExpectation < MessageExpectation
|
321
|
+
def initialize(message, expectation_ordering, expected_from, sym, method_block)
|
322
|
+
super(message, expectation_ordering, expected_from, sym, method_block, 0)
|
323
|
+
end
|
324
|
+
|
325
|
+
def negative_expectation_for?(sym)
|
326
|
+
return @sym == sym
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
end
|
331
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Spec
|
2
|
+
module Mocks
|
3
|
+
module Methods
|
4
|
+
def should_receive(sym, opts={}, &block)
|
5
|
+
__mock_proxy.add_message_expectation(opts[:expected_from] || caller(1)[0], sym.to_sym, opts, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def should_not_receive(sym, &block)
|
9
|
+
__mock_proxy.add_negative_message_expectation(caller(1)[0], sym.to_sym, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub!(sym_or_hash, opts={})
|
13
|
+
if Hash === sym_or_hash
|
14
|
+
sym_or_hash.each {|method, value| stub!(method).and_return value }
|
15
|
+
else
|
16
|
+
__mock_proxy.add_stub(caller(1)[0], sym_or_hash.to_sym, opts)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def received_message?(sym, *args, &block) #:nodoc:
|
21
|
+
__mock_proxy.received_message?(sym.to_sym, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def rspec_verify #:nodoc:
|
25
|
+
__mock_proxy.verify
|
26
|
+
end
|
27
|
+
|
28
|
+
def rspec_reset #:nodoc:
|
29
|
+
__mock_proxy.reset
|
30
|
+
end
|
31
|
+
|
32
|
+
def as_null_object
|
33
|
+
__mock_proxy.as_null_object
|
34
|
+
end
|
35
|
+
|
36
|
+
def null_object?
|
37
|
+
__mock_proxy.null_object?
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def __mock_proxy
|
43
|
+
if Mock === self
|
44
|
+
@mock_proxy ||= Proxy.new(self, @name, @options)
|
45
|
+
else
|
46
|
+
@mock_proxy ||= Proxy.new(self)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Spec
|
2
|
+
module Mocks
|
3
|
+
class Mock
|
4
|
+
include Methods
|
5
|
+
|
6
|
+
# Creates a new mock with a +name+ (that will be used in error messages
|
7
|
+
# only) == Options:
|
8
|
+
# * <tt>:null_object</tt> - if true, the mock object acts as a forgiving
|
9
|
+
# null object allowing any message to be sent to it.
|
10
|
+
def initialize(name, stubs_and_options={})
|
11
|
+
@name = name
|
12
|
+
@options = parse_options(stubs_and_options)
|
13
|
+
assign_stubs(stubs_and_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# This allows for comparing the mock to other objects that proxy such as
|
17
|
+
# ActiveRecords belongs_to proxy objects. By making the other object run
|
18
|
+
# the comparison, we're sure the call gets delegated to the proxy
|
19
|
+
# target.
|
20
|
+
def ==(other)
|
21
|
+
other == __mock_proxy
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(sym, *args, &block)
|
25
|
+
__mock_proxy.record_message_received(sym, args, block)
|
26
|
+
begin
|
27
|
+
return self if __mock_proxy.null_object?
|
28
|
+
super(sym, *args, &block)
|
29
|
+
rescue NameError
|
30
|
+
__mock_proxy.raise_unexpected_message_error sym, *args
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def inspect
|
35
|
+
"#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>"
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
inspect.gsub('<','[').gsub('>',']')
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def parse_options(options)
|
45
|
+
options.has_key?(:null_object) ? {:null_object => options.delete(:null_object)} : {}
|
46
|
+
end
|
47
|
+
|
48
|
+
def assign_stubs(stubs)
|
49
|
+
stubs.each_pair do |message, response|
|
50
|
+
stub!(message).and_return(response)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Spec
|
2
|
+
module Mocks
|
3
|
+
class OrderGroup
|
4
|
+
def initialize error_generator
|
5
|
+
@error_generator = error_generator
|
6
|
+
@ordering = Array.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def register(expectation)
|
10
|
+
@ordering << expectation
|
11
|
+
end
|
12
|
+
|
13
|
+
def ready_for?(expectation)
|
14
|
+
return @ordering.first == expectation
|
15
|
+
end
|
16
|
+
|
17
|
+
def consume
|
18
|
+
@ordering.shift
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle_order_constraint expectation
|
22
|
+
return unless @ordering.include? expectation
|
23
|
+
return consume if ready_for?(expectation)
|
24
|
+
@error_generator.raise_out_of_order_error expectation.sym
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
module Spec
|
2
|
+
module Mocks
|
3
|
+
class Proxy
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
:null_object => false,
|
6
|
+
}
|
7
|
+
|
8
|
+
@@warn_about_expectations_on_nil = true
|
9
|
+
|
10
|
+
def self.allow_message_expectations_on_nil
|
11
|
+
@@warn_about_expectations_on_nil = false
|
12
|
+
|
13
|
+
# ensure nil.rspec_verify is called even if an expectation is not set in the example
|
14
|
+
# otherwise the allowance would effect subsequent examples
|
15
|
+
$rspec_mocks.add(nil) unless $rspec_mocks.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(target, name=nil, options={})
|
19
|
+
@target = target
|
20
|
+
@name = name
|
21
|
+
@error_generator = ErrorGenerator.new target, name
|
22
|
+
@expectation_ordering = OrderGroup.new @error_generator
|
23
|
+
@expectations = []
|
24
|
+
@messages_received = []
|
25
|
+
@stubs = []
|
26
|
+
@proxied_methods = []
|
27
|
+
@options = options ? DEFAULT_OPTIONS.dup.merge(options) : DEFAULT_OPTIONS
|
28
|
+
end
|
29
|
+
|
30
|
+
def null_object?
|
31
|
+
@options[:null_object]
|
32
|
+
end
|
33
|
+
|
34
|
+
def as_null_object
|
35
|
+
@options[:null_object] = true
|
36
|
+
@target
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_message_expectation(expected_from, sym, opts={}, &block)
|
40
|
+
__add sym
|
41
|
+
warn_if_nil_class sym
|
42
|
+
if existing_stub = @stubs.detect {|s| s.sym == sym }
|
43
|
+
expectation = existing_stub.build_child(expected_from, block_given?? block : nil, 1, opts)
|
44
|
+
else
|
45
|
+
expectation = MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
|
46
|
+
end
|
47
|
+
@expectations << expectation
|
48
|
+
@expectations.last
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_negative_message_expectation(expected_from, sym, &block)
|
52
|
+
__add sym
|
53
|
+
warn_if_nil_class sym
|
54
|
+
@expectations << NegativeMessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil)
|
55
|
+
@expectations.last
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_stub(expected_from, sym, opts={})
|
59
|
+
__add sym
|
60
|
+
@stubs.unshift MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, nil, :any, opts)
|
61
|
+
@stubs.first
|
62
|
+
end
|
63
|
+
|
64
|
+
def verify #:nodoc:
|
65
|
+
verify_expectations
|
66
|
+
ensure
|
67
|
+
reset
|
68
|
+
end
|
69
|
+
|
70
|
+
def reset
|
71
|
+
clear_expectations
|
72
|
+
clear_stubs
|
73
|
+
reset_proxied_methods
|
74
|
+
clear_proxied_methods
|
75
|
+
reset_nil_expectations_warning
|
76
|
+
end
|
77
|
+
|
78
|
+
def received_message?(sym, *args, &block)
|
79
|
+
@messages_received.any? {|array| array == [sym, args, block]}
|
80
|
+
end
|
81
|
+
|
82
|
+
def has_negative_expectation?(sym)
|
83
|
+
@expectations.detect {|expectation| expectation.negative_expectation_for?(sym)}
|
84
|
+
end
|
85
|
+
|
86
|
+
def record_message_received(sym, args, block)
|
87
|
+
@messages_received << [sym, args, block]
|
88
|
+
end
|
89
|
+
|
90
|
+
def message_received(sym, *args, &block)
|
91
|
+
expectation = find_matching_expectation(sym, *args)
|
92
|
+
stub = find_matching_method_stub(sym, *args)
|
93
|
+
|
94
|
+
if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
|
95
|
+
if expectation = find_almost_matching_expectation(sym, *args)
|
96
|
+
expectation.advise(args, block) unless expectation.expected_messages_received?
|
97
|
+
end
|
98
|
+
stub.invoke(args, block)
|
99
|
+
elsif expectation
|
100
|
+
expectation.invoke(args, block)
|
101
|
+
elsif expectation = find_almost_matching_expectation(sym, *args)
|
102
|
+
expectation.advise(args, block) if null_object? unless expectation.expected_messages_received?
|
103
|
+
raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(sym) or null_object?)
|
104
|
+
else
|
105
|
+
@target.__send__ :method_missing, sym, *args, &block
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def raise_unexpected_message_args_error(expectation, *args)
|
110
|
+
@error_generator.raise_unexpected_message_args_error expectation, *args
|
111
|
+
end
|
112
|
+
|
113
|
+
def raise_unexpected_message_error(sym, *args)
|
114
|
+
@error_generator.raise_unexpected_message_error sym, *args
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def __add(sym)
|
120
|
+
$rspec_mocks.add(@target) unless $rspec_mocks.nil?
|
121
|
+
define_expected_method(sym)
|
122
|
+
end
|
123
|
+
|
124
|
+
def warn_if_nil_class(sym)
|
125
|
+
if proxy_for_nil_class? && @@warn_about_expectations_on_nil
|
126
|
+
Kernel.warn("An expectation of :#{sym} was set on nil. Called from #{caller[2]}. Use allow_message_expectations_on_nil to disable warnings.")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def define_expected_method(sym)
|
131
|
+
visibility_string = "#{visibility(sym)} :#{sym}"
|
132
|
+
unless @proxied_methods.include?(sym)
|
133
|
+
if target_responds_to?(sym)
|
134
|
+
munged_sym = munge(sym)
|
135
|
+
target_metaclass.instance_eval do
|
136
|
+
alias_method munged_sym, sym if method_defined?(sym.to_s)
|
137
|
+
end
|
138
|
+
@proxied_methods << sym
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
target_metaclass.class_eval(<<-EOF, __FILE__, __LINE__)
|
143
|
+
def #{sym}(*args, &block)
|
144
|
+
__mock_proxy.message_received :#{sym}, *args, &block
|
145
|
+
end
|
146
|
+
#{visibility_string}
|
147
|
+
EOF
|
148
|
+
end
|
149
|
+
|
150
|
+
def target_responds_to?(sym)
|
151
|
+
return @target.__send__(munge(:respond_to?),sym) if @already_proxied_respond_to
|
152
|
+
return @already_proxied_respond_to = true if sym == :respond_to?
|
153
|
+
return @target.respond_to?(sym, true)
|
154
|
+
end
|
155
|
+
|
156
|
+
def visibility(sym)
|
157
|
+
if Mock === @target
|
158
|
+
'public'
|
159
|
+
elsif target_metaclass.private_method_defined?(sym)
|
160
|
+
'private'
|
161
|
+
elsif target_metaclass.protected_method_defined?(sym)
|
162
|
+
'protected'
|
163
|
+
else
|
164
|
+
'public'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def munge(sym)
|
169
|
+
"proxied_by_rspec__#{sym.to_s}".to_sym
|
170
|
+
end
|
171
|
+
|
172
|
+
def clear_expectations
|
173
|
+
@expectations.clear
|
174
|
+
end
|
175
|
+
|
176
|
+
def clear_stubs
|
177
|
+
@stubs.clear
|
178
|
+
end
|
179
|
+
|
180
|
+
def clear_proxied_methods
|
181
|
+
@proxied_methods.clear
|
182
|
+
end
|
183
|
+
|
184
|
+
def target_metaclass
|
185
|
+
class << @target; self; end
|
186
|
+
end
|
187
|
+
|
188
|
+
def verify_expectations
|
189
|
+
@expectations.each do |expectation|
|
190
|
+
expectation.verify_messages_received
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def reset_proxied_methods
|
195
|
+
@proxied_methods.each do |sym|
|
196
|
+
munged_sym = munge(sym)
|
197
|
+
target_metaclass.instance_eval do
|
198
|
+
if method_defined?(munged_sym.to_s)
|
199
|
+
alias_method sym, munged_sym
|
200
|
+
undef_method munged_sym
|
201
|
+
else
|
202
|
+
remove_method sym
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def proxy_for_nil_class?
|
209
|
+
@target.nil?
|
210
|
+
end
|
211
|
+
|
212
|
+
def reset_nil_expectations_warning
|
213
|
+
@@warn_about_expectations_on_nil = true if proxy_for_nil_class?
|
214
|
+
end
|
215
|
+
|
216
|
+
def find_matching_expectation(sym, *args)
|
217
|
+
@expectations.find {|expectation| expectation.matches(sym, args)}
|
218
|
+
end
|
219
|
+
|
220
|
+
def find_almost_matching_expectation(sym, *args)
|
221
|
+
@expectations.find {|expectation| expectation.matches_name_but_not_args(sym, args)}
|
222
|
+
end
|
223
|
+
|
224
|
+
def find_matching_method_stub(sym, *args)
|
225
|
+
@stubs.find {|stub| stub.matches(sym, args)}
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|