mocha 1.10.2 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +28 -30
- data/RELEASE.md +87 -0
- data/Rakefile +7 -5
- data/lib/mocha/api.rb +2 -3
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +30 -27
- data/lib/mocha/configuration.rb +2 -2
- data/lib/mocha/expectation.rb +71 -30
- data/lib/mocha/inspect.rb +6 -4
- data/lib/mocha/invocation.rb +9 -5
- data/lib/mocha/mock.rb +41 -15
- data/lib/mocha/mockery.rb +17 -27
- data/lib/mocha/parameter_matchers.rb +1 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
- data/lib/mocha/parameter_matchers/has_entry.rb +24 -16
- data/lib/mocha/parameter_matchers/has_key.rb +2 -3
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +2 -3
- data/lib/mocha/parameter_matchers/is_a.rb +2 -3
- data/lib/mocha/parameter_matchers/not.rb +2 -3
- data/lib/mocha/state_machine.rb +31 -40
- data/lib/mocha/stubbed_method.rb +4 -6
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +5 -11
- data/mocha.gemspec +13 -7
- metadata +8 -210
- data/bin/build-matrix +0 -82
- data/docs/CNAME +0 -1
- data/docs/Mocha.html +0 -254
- data/docs/Mocha/API.html +0 -1287
- data/docs/Mocha/ClassMethods.html +0 -264
- data/docs/Mocha/Configuration.html +0 -1525
- data/docs/Mocha/Expectation.html +0 -2654
- 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 -1237
- data/docs/Mocha/ObjectMethods.html +0 -765
- data/docs/Mocha/ParameterMatchers.html +0 -2961
- 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 -974
- 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 -635
- data/docs/top-level-namespace.html +0 -118
- data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.5.11.3 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/lib/mocha/multiple_yields.rb +0 -15
- data/lib/mocha/no_yields.rb +0 -5
- data/lib/mocha/pretty_parameters.rb +0 -24
- data/lib/mocha/single_yield.rb +0 -13
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- 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 -61
- data/test/acceptance/issue_272_test.rb +0 -50
- 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 -96
- data/test/acceptance/mocha_test_result_test.rb +0 -83
- data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -99
- data/test/acceptance/mock_test.rb +0 -139
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
- 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 -93
- 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/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 -492
- 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/multiple_yields_test.rb +0 -16
- data/test/unit/no_yields_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/single_yield_test.rb +0 -16
- 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 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77366bffa410729ac6089097db85ded323e74d1ec7bc6eb0ea13ae4a18b44eac
|
4
|
+
data.tar.gz: f9f3c89bbc29393e99ec62e0d1395ed4fa4863d0f790d24bbe6be3537450e4c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91e277be3c868ef2f6655016a53f040835b8e9d6390c789b6f047be72e9b96726865eefcb161b86d0f8e89ead1c58e9adbf1a1cbcdf9cba8a0f0b536de86222d
|
7
|
+
data.tar.gz: 4b7bf751e350762a5a3d9cd17fbe1a590ff5122a718417b75304fa86f8323b20652a24584cedabd859395aeef004402e57c70c15cd88746032659b0d9df4cccf
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: floehopper
|
data/.yardopts
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -3,5 +3,5 @@
|
|
3
3
|
* Make your changes in a branch.
|
4
4
|
* Add/modify/remove tests as appropriate.
|
5
5
|
* Open a pull request based on a branch on your fork.
|
6
|
-
* Wait for your pull request build to pass on [
|
6
|
+
* Wait for your pull request build to pass on [Circle CI](https://app.circleci.com/pipelines/github/freerange/mocha).
|
7
7
|
* Pull requests with failing tests will not be accepted.
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
## Mocha [![
|
2
|
-
|
1
|
+
## Mocha [![CircleCI status of freerange/mocha](https://circleci.com/gh/freerange/mocha.svg?style=shield&circle-token=bc1f6576c77da43ec58badde9273fa4eb1d7f53a)](https://app.circleci.com/pipelines/github/freerange/mocha) [![Gem Version](https://badge.fury.io/rb/mocha.svg)](http://badge.fury.io/rb/mocha) [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=mocha&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=mocha&package-manager=bundler&version-scheme=semver)
|
3
2
|
|
4
3
|
### Description
|
5
4
|
|
@@ -47,35 +46,21 @@ If you're using Bundler, include Mocha in the `Gemfile` and then setup Mocha lat
|
|
47
46
|
|
48
47
|
```ruby
|
49
48
|
# Gemfile
|
50
|
-
gem
|
49
|
+
gem 'mocha'
|
51
50
|
|
52
51
|
# Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
|
53
|
-
require
|
54
|
-
require
|
52
|
+
require 'test/unit'
|
53
|
+
require 'mocha/test_unit'
|
55
54
|
```
|
56
55
|
|
57
56
|
##### MiniTest
|
58
57
|
|
59
58
|
```ruby
|
60
59
|
# Gemfile
|
61
|
-
gem "mocha"
|
62
|
-
|
63
|
-
# Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
|
64
|
-
require "minitest/unit"
|
65
|
-
require "mocha/minitest"
|
66
|
-
```
|
67
|
-
|
68
|
-
#### Rails
|
69
|
-
|
70
|
-
If you're loading Mocha using Bundler within a Rails application, you should setup Mocha manually e.g. at the bottom of your `test_helper.rb`.
|
71
|
-
|
72
|
-
##### MiniTest
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
# Gemfile in Rails app
|
76
60
|
gem 'mocha'
|
77
61
|
|
78
|
-
#
|
62
|
+
# Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
|
63
|
+
require 'minitest/unit'
|
79
64
|
require 'mocha/minitest'
|
80
65
|
```
|
81
66
|
|
@@ -95,13 +80,6 @@ end
|
|
95
80
|
|
96
81
|
Note: There is no need to use a require statement to setup Mocha; RSpec does this itself.
|
97
82
|
|
98
|
-
##### MiniTest
|
99
|
-
|
100
|
-
```ruby
|
101
|
-
# At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
|
102
|
-
require 'mocha/minitest'
|
103
|
-
```
|
104
|
-
|
105
83
|
##### Cucumber
|
106
84
|
|
107
85
|
```ruby
|
@@ -121,9 +99,29 @@ Around do |scenario, block|
|
|
121
99
|
end
|
122
100
|
```
|
123
101
|
|
102
|
+
#### Rails
|
103
|
+
|
104
|
+
If you're loading Mocha using Bundler within a Rails application, you should setup Mocha manually e.g. at the bottom of your `test_helper.rb`.
|
105
|
+
|
106
|
+
##### MiniTest
|
107
|
+
|
108
|
+
Note that since Rails v4 (at least), `ActiveSupport::TestCase` has inherited from `Minitest::Test` or its earlier equivalents. Thus unless you are *explicitly* using Test::Unit, you are likely to be using MiniTest.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
# Gemfile in Rails app
|
112
|
+
gem 'mocha'
|
113
|
+
|
114
|
+
# At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
|
115
|
+
require 'mocha/minitest'
|
116
|
+
```
|
117
|
+
|
118
|
+
##### Other Test Framework
|
119
|
+
|
120
|
+
Follow the instructions for the relevant test framework in the [Bundler](#bundler) section, but ensure that the relevant Mocha file (`mocha/minitest`, `mocha/test_unit`, or `mocha/api`) is required **after** the test framework has been loaded, e.g. at the bottom of `test_helper.rb` or `spec_helper.rb`, or at least after `rails/test_help` has been required.
|
121
|
+
|
124
122
|
#### Known Issues
|
125
123
|
|
126
|
-
* In Mocha v1.10.0 an undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` was changed. Previously when these methods were passed a single symbol, they returned a mock object that responded to the method identified by the symbol. Now Passing a single symbol is equivalent to passing a single string, i.e. it now defines the
|
124
|
+
* In Mocha v1.10.0 an undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` was changed. Previously when these methods were passed a single symbol, they returned a mock object that responded to the method identified by the symbol. Now Passing a single symbol is equivalent to passing a single string, i.e. it now defines the 'name' of the mock object.
|
127
125
|
* In Mocha v1.2.0 there is a scenario where stubbing a class method originally defined in a module hangs the Ruby interpreter due to [a bug in Ruby v2.3.1](https://bugs.ruby-lang.org/issues/12832). See #272. This was fixed in Mocha v1.2.1.
|
128
126
|
* Since v1.1.0 Mocha has used prepended modules internally for stubbing methods. There is [an obscure Ruby bug](https://bugs.ruby-lang.org/issues/12876) in many (but not all) versions of Ruby between v2.0 & v2.3 which under certain circumstances may cause your Ruby interpreter to hang. See the Ruby bug report for more details. The bug has been fixed in Ruby v2.3.3 & v2.4.0.
|
129
127
|
* Stubbing an aliased class method, where the original method is defined in a module that's used to `extend` the class doesn't work in Ruby 1.8.x. See stub_method_defined_on_module_and_aliased_test.rb for an example of this behaviour.
|
@@ -325,7 +323,7 @@ See this [list of contributors](https://github.com/freerange/mocha/graphs/contri
|
|
325
323
|
* Update the RELEASE.md file with a summary of changes
|
326
324
|
* Bump the version in `lib/mocha/version.rb`
|
327
325
|
* Commit & push to GitHub
|
328
|
-
* Check
|
326
|
+
* Check CircleCI build is passing - https://app.circleci.com/pipelines/github/freerange/mocha
|
329
327
|
|
330
328
|
* Sign in to Google Analytics - https://analytics.google.com/analytics/web/
|
331
329
|
* Find the web property ID for floehopper (625523) > Mocha Documentation (UA-625523-7)
|
data/RELEASE.md
CHANGED
@@ -1,5 +1,92 @@
|
|
1
1
|
# Release Notes
|
2
2
|
|
3
|
+
## 1.13.0
|
4
|
+
|
5
|
+
### External changes
|
6
|
+
|
7
|
+
* Add `ParameterMatchers#has_keys` - thanks to @cstyles for #512 (18d8104)
|
8
|
+
* Fix misleading exception message in `ParameterMatchers#has_entry` - thanks to @cstyles for #513 (9c4ef13)
|
9
|
+
* Only add dependency on rubocop if we're actually going to use it (f2f879f)
|
10
|
+
* Fix rake dependency constraints for older Ruby versions (7ce5f29)
|
11
|
+
|
12
|
+
### Internal changes
|
13
|
+
|
14
|
+
* Check documentation can be generated as part of CircleCI build (b30d9a9)
|
15
|
+
* Add --fail-on-warning option to yard rake task (53a6ee3)
|
16
|
+
* Add a weekly scheduled build to the CircleCI build (fd2a4c6)
|
17
|
+
* Add Ruby v1.8 to the CircleCI build matrix (818ca03)
|
18
|
+
* Add API token to fix CircleCI badge in README (607c5aa)
|
19
|
+
* Provide wrapped option for #mocha_inspect on hashes & arrays (d8f44bc)
|
20
|
+
* Use CircleCI instead of TravisCI for automated builds (c98c6ec)
|
21
|
+
* Switch to newer default Travis CI build env (c78f75c)
|
22
|
+
* Use latest Ruby versions in Travis CI builds (9e0043a)
|
23
|
+
* Use latest JRuby v9.2.18 in Travis CI builds (8c99a1b)
|
24
|
+
* Use consistent JRuby versions in Travis CI builds (0f849aa)
|
25
|
+
* Use more recent version of JRuby in Travis CI build matrix (58653db)
|
26
|
+
|
27
|
+
## 1.12.0
|
28
|
+
|
29
|
+
### External changes
|
30
|
+
|
31
|
+
* Various improvements to README inspired by #207 and #390 - thanks to @nitishr for his work on #390 (fed0eee6)
|
32
|
+
* Improve documentation related to `StateMachine` classes - thanks to @nitishr (#425 & #427)
|
33
|
+
* Fix regression in cardinality introduced in v1.10.0 (59454a8) and reported in #473 - thanks to @srvance for reporting and @nitishr for fixing (#474)
|
34
|
+
* Fix documentation for `Mocha::Expectation#when` - thanks to @olleolleolle (b4f59daa & #477)
|
35
|
+
* Remove `Mocha::Mock#respond_to?` from documentation - thanks to @nitishr (#480)
|
36
|
+
* Improvements to documentation for `Expectation#yields` & `#multiple_yields` - thanks to @andyw8 for reporting in #495 (1b6571c)
|
37
|
+
* Remove documentation & tests from gem to reduce its size by over 50% - thanks to @gabetax (#500)
|
38
|
+
* Update documentation to point to travis-ci.com instead of travis-ci.org
|
39
|
+
|
40
|
+
### Internal changes
|
41
|
+
|
42
|
+
* Refactor `StateMachine`-related classes - thanks to @nitishr (#425 & #427)
|
43
|
+
* Remove redundant test - thanks to @nitishr (8e4f1a7c)
|
44
|
+
* Add Ruby 2.7 to Travis CI matrix - thanks to @bastelfreak (fc5ea2f2)
|
45
|
+
* Simplify `Mockery` - thanks to @nitishr (#449)
|
46
|
+
* Update Travis CI badge to point to main vs master branch (bd8028f8)
|
47
|
+
* Generate docs using newer version of yard (v0.9.25) (c619afac)
|
48
|
+
* Manually upgrade jquery in docs from v1.7.1 -> v1.9.0 to fix CVE-2017-16011 (211098a5, dd5eeedb & 1b76e4d5; also see #492)
|
49
|
+
* Remove reference to non-existent jquery source map to fix error in Chrome developer tools (20156555)
|
50
|
+
* Temporarily ignore Ruby v1.8.7 build failures (e5b9feef)
|
51
|
+
|
52
|
+
## 1.11.2
|
53
|
+
|
54
|
+
### External changes
|
55
|
+
|
56
|
+
* Fix regression introduced in v1.10.0 that meant `Object#inspect` was called unnecessarily (368abd98)
|
57
|
+
* Warn when mock object receives invocations in another test - thanks to @nitishr (#442)
|
58
|
+
* Avoid rubocop comments appearing in YARD-generated docs (d8019eed)
|
59
|
+
|
60
|
+
### Internal changes
|
61
|
+
|
62
|
+
* Replace `StubbedMethod#original_method` & `#original_visibility` attribute reader methods with instance variables - thanks to @nitishr (d917f332)
|
63
|
+
* Set up `MochaExampleTest` & `StubbaExampleTest` as acceptance tests - thanks to @nitishr (4881cc58)
|
64
|
+
* Delete unused `PrettyParameters` class - thanks to @nitishr (314ea922)
|
65
|
+
|
66
|
+
## 1.11.1
|
67
|
+
|
68
|
+
### External changes
|
69
|
+
|
70
|
+
* The `reinstate_undocumented_behaviour_from_v1_9` configuration option is now enabled by default to give people a chance to see and fix the relevant deprecation warnings before the behaviour is removed in a future release (b91b1c9e)
|
71
|
+
|
72
|
+
## 1.11.0
|
73
|
+
|
74
|
+
### External changes
|
75
|
+
|
76
|
+
* Add `Expectation#with_block_given` & `Expectation#with_no_block_given` (#441).
|
77
|
+
* Allows non-deprecated solution for #382. Thanks to @yemartin for reporting and to @techbelly & @nitishr for feedback.
|
78
|
+
* Fix issue with non-Array arguments passed to `Expectation#multiple_yields` (#444).
|
79
|
+
* The undocumented behaviour is now properly supported and documented.
|
80
|
+
|
81
|
+
### Internal changes
|
82
|
+
|
83
|
+
* Move static YARD options from Rake task to `.yardopts` file - thanks to @nitishr (#429)
|
84
|
+
* Simplify implementation of yielding functionality - thanks to @nitishr (#439)
|
85
|
+
* Add missing require statement to `acceptance_test_helper.rb` (1070fc02)
|
86
|
+
* Add some baseline acceptance tests for yielding behaviour (c2cac911)
|
87
|
+
* Display a sponsor button on GitHub repo page (9fc5911b)
|
88
|
+
* Use new Deprecation.warning behaviour in `Invocation#call` (932d1166)
|
89
|
+
|
3
90
|
## 1.10.2
|
4
91
|
|
5
92
|
* Optionally reinstate undocumented behaviour from v1.9. This introduces a new configuration option (`reinstate_undocumented_behaviour_from_v1_9`) to reinstate a couple of bits of undocumented behaviour from v1.9 which were changed in v1.10 without any prior deprecation warning (#438):
|
data/Rakefile
CHANGED
@@ -138,18 +138,20 @@ if ENV['MOCHA_GENERATE_DOCS']
|
|
138
138
|
|
139
139
|
desc 'Generate documentation'
|
140
140
|
YARD::Rake::YardocTask.new('yardoc' => 'docs_environment') do |task|
|
141
|
-
task.options = [
|
142
|
-
'--title', "Mocha #{Mocha::VERSION}",
|
143
|
-
'--output-dir', 'docs'
|
144
|
-
]
|
141
|
+
task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
|
145
142
|
end
|
146
143
|
|
147
144
|
task 'checkout_docs_cname' do
|
148
145
|
`git checkout docs/CNAME`
|
149
146
|
end
|
150
147
|
|
148
|
+
task 'checkout_docs_js' do
|
149
|
+
`git checkout docs/js/app.js`
|
150
|
+
`git checkout docs/js/jquery.js`
|
151
|
+
end
|
152
|
+
|
151
153
|
desc 'Generate documentation'
|
152
|
-
task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname]
|
154
|
+
task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
|
153
155
|
end
|
154
156
|
|
155
157
|
task 'release' => 'default'
|
data/lib/mocha/api.rb
CHANGED
@@ -65,8 +65,8 @@ module Mocha
|
|
65
65
|
# assert motor.stop
|
66
66
|
# # an error will be raised unless both Motor#start and Motor#stop have been called
|
67
67
|
# end
|
68
|
-
#
|
69
|
-
def mock(*arguments)
|
68
|
+
#
|
69
|
+
def mock(*arguments) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
70
70
|
if Mocha.configuration.reinstate_undocumented_behaviour_from_v1_9?
|
71
71
|
if arguments.first.is_a?(Symbol)
|
72
72
|
method_name = arguments[0]
|
@@ -91,7 +91,6 @@ module Mocha
|
|
91
91
|
mock.expects(expectations)
|
92
92
|
mock
|
93
93
|
end
|
94
|
-
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
95
94
|
|
96
95
|
# Builds a new mock object
|
97
96
|
#
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Mocha
|
2
|
+
module BlockMatchers
|
3
|
+
class OptionalBlock
|
4
|
+
def match?(_actual_block)
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
def mocha_inspect; end
|
9
|
+
end
|
10
|
+
|
11
|
+
class BlockGiven
|
12
|
+
def match?(actual_block)
|
13
|
+
!actual_block.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def mocha_inspect
|
17
|
+
'with block given'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class NoBlockGiven
|
22
|
+
def match?(actual_block)
|
23
|
+
actual_block.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def mocha_inspect
|
27
|
+
'with no block given'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/mocha/cardinality.rb
CHANGED
@@ -2,31 +2,28 @@ module Mocha
|
|
2
2
|
class Cardinality
|
3
3
|
INFINITY = 1 / 0.0
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def initialize(required = 0, maximum = INFINITY)
|
6
|
+
update(required, maximum)
|
7
|
+
@invocations = []
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def exactly(count)
|
11
|
+
update(count, count)
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def at_least(count)
|
15
|
+
update(count, INFINITY)
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
when Range then new(range_or_count.first, range_or_count.last)
|
21
|
-
else new(range_or_count, range_or_count)
|
22
|
-
end
|
23
|
-
end
|
18
|
+
def at_most(count)
|
19
|
+
update(0, count)
|
24
20
|
end
|
25
21
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
def times(range_or_count)
|
23
|
+
case range_or_count
|
24
|
+
when Range then update(range_or_count.first, range_or_count.last)
|
25
|
+
else update(range_or_count, range_or_count)
|
26
|
+
end
|
30
27
|
end
|
31
28
|
|
32
29
|
def <<(invocation)
|
@@ -62,21 +59,21 @@ module Mocha
|
|
62
59
|
if allowed_any_number_of_times?
|
63
60
|
'allowed any number of times'
|
64
61
|
elsif required.zero? && maximum.zero?
|
65
|
-
"expected #{
|
62
|
+
"expected #{count(maximum)}"
|
66
63
|
elsif required == maximum
|
67
|
-
"expected exactly #{
|
64
|
+
"expected exactly #{count(required)}"
|
68
65
|
elsif infinite?(maximum)
|
69
|
-
"expected at least #{
|
66
|
+
"expected at least #{count(required)}"
|
70
67
|
elsif required.zero?
|
71
|
-
"expected at most #{
|
68
|
+
"expected at most #{count(maximum)}"
|
72
69
|
else
|
73
|
-
"expected between #{required} and #{
|
70
|
+
"expected between #{required} and #{count(maximum)}"
|
74
71
|
end
|
75
72
|
end
|
76
73
|
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
77
74
|
|
78
75
|
def invoked_times
|
79
|
-
"invoked #{
|
76
|
+
"invoked #{count(@invocations.size)}"
|
80
77
|
end
|
81
78
|
|
82
79
|
def actual_invocations
|
@@ -87,7 +84,7 @@ module Mocha
|
|
87
84
|
|
88
85
|
attr_reader :required, :maximum
|
89
86
|
|
90
|
-
def
|
87
|
+
def count(number)
|
91
88
|
case number
|
92
89
|
when 0 then 'never'
|
93
90
|
when 1 then 'once'
|
@@ -96,6 +93,12 @@ module Mocha
|
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
96
|
+
def update(required, maximum)
|
97
|
+
@required = required
|
98
|
+
@maximum = maximum
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
99
102
|
def infinite?(number)
|
100
103
|
number.respond_to?(:infinite?) && number.infinite?
|
101
104
|
end
|
data/lib/mocha/configuration.rb
CHANGED
@@ -43,7 +43,7 @@ module Mocha
|
|
43
43
|
:stubbing_non_public_method => :allow,
|
44
44
|
:stubbing_method_on_nil => :prevent,
|
45
45
|
:display_matching_invocations_on_failure => false,
|
46
|
-
:reinstate_undocumented_behaviour_from_v1_9 =>
|
46
|
+
:reinstate_undocumented_behaviour_from_v1_9 => true
|
47
47
|
}.freeze
|
48
48
|
|
49
49
|
attr_reader :options
|
@@ -258,7 +258,7 @@ module Mocha
|
|
258
258
|
#
|
259
259
|
# Enabling this configuration option reinstates the previous behaviour, but displays a deprecation warning.
|
260
260
|
#
|
261
|
-
# @param [Boolean] value +true+ to reinstate undocumented behaviour;
|
261
|
+
# @param [Boolean] value +true+ to reinstate undocumented behaviour; enabled by default.
|
262
262
|
#
|
263
263
|
# @example Reinstate undocumented behaviour for {API#mock}
|
264
264
|
# Mocha.configure do |c|
|
data/lib/mocha/expectation.rb
CHANGED
@@ -10,6 +10,7 @@ require 'mocha/in_state_ordering_constraint'
|
|
10
10
|
require 'mocha/change_state_side_effect'
|
11
11
|
require 'mocha/cardinality'
|
12
12
|
require 'mocha/configuration'
|
13
|
+
require 'mocha/block_matcher'
|
13
14
|
|
14
15
|
module Mocha
|
15
16
|
# Methods on expectations returned from {Mock#expects}, {Mock#stubs}, {ObjectMethods#expects} and {ObjectMethods#stubs}.
|
@@ -41,7 +42,7 @@ module Mocha
|
|
41
42
|
# object.expected_method
|
42
43
|
# # => verify fails
|
43
44
|
def times(range)
|
44
|
-
@cardinality
|
45
|
+
@cardinality.times(range)
|
45
46
|
self
|
46
47
|
end
|
47
48
|
|
@@ -67,7 +68,7 @@ module Mocha
|
|
67
68
|
# object.expected_method
|
68
69
|
# # => verify fails
|
69
70
|
def twice
|
70
|
-
@cardinality
|
71
|
+
@cardinality.exactly(2)
|
71
72
|
self
|
72
73
|
end
|
73
74
|
|
@@ -92,7 +93,7 @@ module Mocha
|
|
92
93
|
# object.expects(:expected_method).once
|
93
94
|
# # => verify fails
|
94
95
|
def once
|
95
|
-
@cardinality
|
96
|
+
@cardinality.exactly(1)
|
96
97
|
self
|
97
98
|
end
|
98
99
|
|
@@ -109,7 +110,7 @@ module Mocha
|
|
109
110
|
# object.expects(:expected_method).never
|
110
111
|
# # => verify succeeds
|
111
112
|
def never
|
112
|
-
@cardinality
|
113
|
+
@cardinality.exactly(0)
|
113
114
|
self
|
114
115
|
end
|
115
116
|
|
@@ -129,7 +130,7 @@ module Mocha
|
|
129
130
|
# object.expected_method
|
130
131
|
# # => verify fails
|
131
132
|
def at_least(minimum_number_of_times)
|
132
|
-
@cardinality
|
133
|
+
@cardinality.at_least(minimum_number_of_times)
|
133
134
|
self
|
134
135
|
end
|
135
136
|
|
@@ -148,7 +149,6 @@ module Mocha
|
|
148
149
|
# # => verify fails
|
149
150
|
def at_least_once
|
150
151
|
at_least(1)
|
151
|
-
self
|
152
152
|
end
|
153
153
|
|
154
154
|
# Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
|
@@ -166,7 +166,7 @@ module Mocha
|
|
166
166
|
# object.expects(:expected_method).at_most(2)
|
167
167
|
# 3.times { object.expected_method } # => unexpected invocation
|
168
168
|
def at_most(maximum_number_of_times)
|
169
|
-
@cardinality
|
169
|
+
@cardinality.at_most(maximum_number_of_times)
|
170
170
|
self
|
171
171
|
end
|
172
172
|
|
@@ -185,7 +185,6 @@ module Mocha
|
|
185
185
|
# 2.times { object.expected_method } # => unexpected invocation
|
186
186
|
def at_most_once
|
187
187
|
at_most(1)
|
188
|
-
self
|
189
188
|
end
|
190
189
|
|
191
190
|
# Modifies expectation so that the expected method must be called with +expected_parameters+.
|
@@ -224,7 +223,49 @@ module Mocha
|
|
224
223
|
self
|
225
224
|
end
|
226
225
|
|
227
|
-
# Modifies expectation so that
|
226
|
+
# Modifies expectation so that the expected method must be called with a block.
|
227
|
+
#
|
228
|
+
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
|
229
|
+
#
|
230
|
+
# @example Expected method must be called with a block.
|
231
|
+
# object = mock()
|
232
|
+
# object.expects(:expected_method).with_block_given
|
233
|
+
# object.expected_method { 1 + 1 }
|
234
|
+
# # => verify succeeds
|
235
|
+
#
|
236
|
+
# object = mock()
|
237
|
+
# object.expects(:expected_method).with_block_given
|
238
|
+
# object.expected_method
|
239
|
+
# # => verify fails
|
240
|
+
def with_block_given
|
241
|
+
@block_matcher = BlockMatchers::BlockGiven.new
|
242
|
+
self
|
243
|
+
end
|
244
|
+
|
245
|
+
# Modifies expectation so that the expected method must be called without a block.
|
246
|
+
#
|
247
|
+
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
|
248
|
+
#
|
249
|
+
# @example Expected method must be called without a block.
|
250
|
+
# object = mock()
|
251
|
+
# object.expects(:expected_method).with_no_block_given
|
252
|
+
# object.expected_method
|
253
|
+
# # => verify succeeds
|
254
|
+
#
|
255
|
+
# object = mock()
|
256
|
+
# object.expects(:expected_method).with_block_given
|
257
|
+
# object.expected_method { 1 + 1 }
|
258
|
+
# # => verify fails
|
259
|
+
def with_no_block_given
|
260
|
+
@block_matcher = BlockMatchers::NoBlockGiven.new
|
261
|
+
self
|
262
|
+
end
|
263
|
+
|
264
|
+
# Modifies expectation so that when the expected method is called, it yields to the block with the specified +parameters+.
|
265
|
+
#
|
266
|
+
# If no +parameters+ are specified, it yields to the block without any parameters.
|
267
|
+
#
|
268
|
+
# If no block is provided, the method will still attempt to yield resulting in a +LocalJumpError+. Note that this is what would happen if a "real" (non-mock) method implementation tried to yield to a non-existent block.
|
228
269
|
#
|
229
270
|
# May be called multiple times on the same expectation for consecutive invocations.
|
230
271
|
#
|
@@ -234,11 +275,10 @@ module Mocha
|
|
234
275
|
#
|
235
276
|
# @example Yield when expected method is invoked.
|
236
277
|
# benchmark = mock()
|
237
|
-
# benchmark.expects(:measure).yields
|
278
|
+
# benchmark.expects(:measure).yields
|
238
279
|
# yielded = false
|
239
|
-
#
|
280
|
+
# benchmark.measure { yielded = true }
|
240
281
|
# yielded # => true
|
241
|
-
# returned_value # => '0.350000 0.400000 0.750000 ( 0.835234)'
|
242
282
|
#
|
243
283
|
# @example Yield parameters when expected method is invoked.
|
244
284
|
# fibonacci = mock()
|
@@ -256,13 +296,14 @@ module Mocha
|
|
256
296
|
# fibonacci.next_pair { |first, second| sum = first + second }
|
257
297
|
# sum # => 2
|
258
298
|
def yields(*parameters)
|
259
|
-
|
260
|
-
self
|
299
|
+
multiple_yields(parameters)
|
261
300
|
end
|
262
301
|
|
263
|
-
# Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups
|
302
|
+
# Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+.
|
303
|
+
#
|
304
|
+
# If no block is provided, the method will still attempt to yield resulting in a +LocalJumpError+. Note that this is what would happen if a "real" (non-mock) method implementation tried to yield to a non-existent block.
|
264
305
|
#
|
265
|
-
# @param [*Array<Array>] parameter_groups each element of +parameter_groups+ should iself be an +Array+ representing the parameters to be passed to the block for a single yield.
|
306
|
+
# @param [*Array<Array>] parameter_groups each element of +parameter_groups+ should iself be an +Array+ representing the parameters to be passed to the block for a single yield. Any element of +parameter_groups+ that is not an +Array+ is wrapped in an +Array+.
|
266
307
|
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
|
267
308
|
# @see #then
|
268
309
|
#
|
@@ -283,7 +324,7 @@ module Mocha
|
|
283
324
|
# rows_from_first_invocation # => [['old_row1_col1', 'old_row1_col2'], ['old_row2_col1', '']]
|
284
325
|
# rows_from_second_invocation # => [['new_row1_col1', ''], ['new_row2_col1', 'new_row2_col2']]
|
285
326
|
def multiple_yields(*parameter_groups)
|
286
|
-
@yield_parameters.
|
327
|
+
@yield_parameters.add(*parameter_groups)
|
287
328
|
self
|
288
329
|
end
|
289
330
|
|
@@ -415,9 +456,9 @@ module Mocha
|
|
415
456
|
|
416
457
|
# @overload def then
|
417
458
|
# Used as syntactic sugar to improve readability. It has no effect on state of the expectation.
|
418
|
-
# @overload def then(
|
419
|
-
# Used to change the +state_machine+ to the
|
420
|
-
# @param [StateMachine::State] state_machine.is(state_name) provides a mechanism to change the +state_machine+ into the state specified by +state_name+ when the expected method is invoked.
|
459
|
+
# @overload def then(state)
|
460
|
+
# Used to change the +state_machine+ to the specified state when the expected invocation occurs.
|
461
|
+
# @param [StateMachine::State] state state_machine.is(state_name) provides a mechanism to change the +state_machine+ into the state specified by +state_name+ when the expected method is invoked.
|
421
462
|
#
|
422
463
|
# @see API#states
|
423
464
|
# @see StateMachine
|
@@ -443,17 +484,14 @@ module Mocha
|
|
443
484
|
# radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
|
444
485
|
# radio.expects(:adjust_volume).with(-5).when(power.is('on'))
|
445
486
|
# radio.expects(:switch_off).then(power.is('off'))
|
446
|
-
def then(
|
447
|
-
|
448
|
-
state = parameters.first
|
449
|
-
add_side_effect(ChangeStateSideEffect.new(state))
|
450
|
-
end
|
487
|
+
def then(state = nil)
|
488
|
+
add_side_effect(ChangeStateSideEffect.new(state)) if state
|
451
489
|
self
|
452
490
|
end
|
453
491
|
|
454
|
-
# Constrains the expectation to occur only when the +state_machine+ is in the state specified by +
|
492
|
+
# Constrains the expectation to occur only when the +state_machine+ is in the state specified by +state_predicate+.
|
455
493
|
#
|
456
|
-
# @param [StateMachine::StatePredicate] state_machine.is(state_name) provides a mechanism to determine whether the +state_machine+ is in the state specified by +
|
494
|
+
# @param [StateMachine::StatePredicate] state_predicate +state_machine.is(state_name)+ provides a mechanism to determine whether the +state_machine+ is in the state specified by +state_predicate+ when the expected method is invoked.
|
457
495
|
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
|
458
496
|
#
|
459
497
|
# @see API#states
|
@@ -511,9 +549,10 @@ module Mocha
|
|
511
549
|
@mock = mock
|
512
550
|
@method_matcher = MethodMatcher.new(expected_method_name.to_sym)
|
513
551
|
@parameters_matcher = ParametersMatcher.new
|
552
|
+
@block_matcher = BlockMatchers::OptionalBlock.new
|
514
553
|
@ordering_constraints = []
|
515
554
|
@side_effects = []
|
516
|
-
@cardinality = Cardinality.exactly(1)
|
555
|
+
@cardinality = Cardinality.new.exactly(1)
|
517
556
|
@return_values = ReturnValues.new
|
518
557
|
@yield_parameters = YieldParameters.new
|
519
558
|
@backtrace = backtrace || caller
|
@@ -551,7 +590,7 @@ module Mocha
|
|
551
590
|
|
552
591
|
# @private
|
553
592
|
def match?(invocation)
|
554
|
-
@method_matcher.match?(invocation.method_name) && @parameters_matcher.match?(invocation.arguments) && in_correct_order?
|
593
|
+
@method_matcher.match?(invocation.method_name) && @parameters_matcher.match?(invocation.arguments) && @block_matcher.match?(invocation.block) && in_correct_order?
|
555
594
|
end
|
556
595
|
|
557
596
|
# @private
|
@@ -601,7 +640,9 @@ module Mocha
|
|
601
640
|
|
602
641
|
# @private
|
603
642
|
def method_signature
|
604
|
-
"#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
|
643
|
+
signature = "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
|
644
|
+
signature << " #{@block_matcher.mocha_inspect}" if @block_matcher.mocha_inspect
|
645
|
+
signature
|
605
646
|
end
|
606
647
|
end
|
607
648
|
end
|