mocha 3.0.0.pre.rc.1 → 3.0.0.pre.rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -37
- data/.yardopts +2 -0
- data/Gemfile +2 -5
- data/RELEASE.md +42 -0
- data/Rakefile +39 -19
- data/lib/mocha/any_instance_method.rb +4 -4
- data/lib/mocha/api.rb +1 -1
- data/lib/mocha/class_methods.rb +9 -5
- data/lib/mocha/configuration.rb +1 -1
- data/lib/mocha/deprecation.rb +1 -1
- data/lib/mocha/expectation.rb +2 -2
- data/lib/mocha/expectation_list.rb +1 -1
- data/lib/mocha/hooks.rb +4 -4
- data/lib/mocha/ignoring_warning.rb +20 -0
- data/lib/mocha/instance_method.rb +4 -4
- data/lib/mocha/integration/minitest/adapter.rb +4 -3
- data/lib/mocha/integration/minitest.rb +1 -1
- data/lib/mocha/integration/test_unit/adapter.rb +7 -4
- data/lib/mocha/integration/test_unit.rb +1 -1
- data/lib/mocha/integration.rb +5 -0
- data/lib/mocha/mock.rb +8 -4
- data/lib/mocha/mockery.rb +20 -12
- data/lib/mocha/object_methods.rb +13 -1
- data/lib/mocha/parameter_matchers/all_of.rb +24 -22
- data/lib/mocha/parameter_matchers/any_of.rb +30 -28
- data/lib/mocha/parameter_matchers/any_parameters.rb +22 -20
- data/lib/mocha/parameter_matchers/anything.rb +19 -17
- data/lib/mocha/parameter_matchers/{base.rb → base_methods.rb} +6 -4
- data/lib/mocha/parameter_matchers/equals.rb +25 -23
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +28 -24
- data/lib/mocha/parameter_matchers/has_entries.rb +25 -23
- data/lib/mocha/parameter_matchers/has_entry.rb +66 -66
- data/lib/mocha/parameter_matchers/has_key.rb +25 -23
- data/lib/mocha/parameter_matchers/has_keys.rb +25 -23
- data/lib/mocha/parameter_matchers/has_value.rb +25 -23
- data/lib/mocha/parameter_matchers/includes.rb +63 -61
- data/lib/mocha/parameter_matchers/instance_methods.rb +2 -2
- data/lib/mocha/parameter_matchers/instance_of.rb +25 -23
- data/lib/mocha/parameter_matchers/is_a.rb +26 -24
- data/lib/mocha/parameter_matchers/kind_of.rb +25 -23
- data/lib/mocha/parameter_matchers/not.rb +25 -23
- data/lib/mocha/parameter_matchers/optionally.rb +35 -33
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +2 -2
- data/lib/mocha/parameter_matchers/regexp_matches.rb +25 -23
- data/lib/mocha/parameter_matchers/responds_with.rb +49 -47
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +24 -22
- data/lib/mocha/parameter_matchers.rb +5 -2
- data/lib/mocha/state_machine.rb +1 -1
- data/lib/mocha/stubbed_method.rb +7 -7
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha.rb +15 -0
- metadata +9 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 89867d8324e0ff09c1b10c13bb46ecbc68215098b8abd916d5be2ebe165d91fe
|
|
4
|
+
data.tar.gz: 835f460adaa854163671e2a2222f68e8674edb1eb80d714f8e7e58ce26705391
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ead2dc30052a85e96ad27728852ee61c120b40229c376508595a09eeee10c863fae71644c4abe917d2a2ae400690d67fd32774a2c4dc6d79fbacc443171d55a
|
|
7
|
+
data.tar.gz: 3cc439692bc5163961fc2cd44aee804634fdb903d01b245e1101c99818f92cb760c51d3a0dd0a8927bc7c29ccf1c0c202bda4cbd70a058c1c21c1a5beb341edb
|
data/.rubocop.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
plugins:
|
|
2
2
|
- rubocop-rake
|
|
3
3
|
|
|
4
4
|
inherit_from: .rubocop_todo.yml
|
|
@@ -11,10 +11,10 @@ AllCops:
|
|
|
11
11
|
TargetRubyVersion: 2.2
|
|
12
12
|
|
|
13
13
|
Include:
|
|
14
|
-
-
|
|
14
|
+
- "**/Gemfile.*"
|
|
15
15
|
|
|
16
16
|
Exclude:
|
|
17
|
-
-
|
|
17
|
+
- "**/Gemfile*.lock"
|
|
18
18
|
|
|
19
19
|
NewCops: enable
|
|
20
20
|
|
|
@@ -72,37 +72,6 @@ Layout/LineLength:
|
|
|
72
72
|
Gemspec/RequiredRubyVersion:
|
|
73
73
|
Enabled: false
|
|
74
74
|
|
|
75
|
-
# It can be useful to violate this cop in tests in order to be more explicit
|
|
76
|
-
Lint/UselessTimes:
|
|
77
|
-
Exclude:
|
|
78
|
-
- 'test/**/*.rb'
|
|
79
|
-
|
|
80
|
-
# It can be useful to violate this cop in tests
|
|
81
|
-
Lint/EmptyClass:
|
|
82
|
-
Exclude:
|
|
83
|
-
- 'test/**/*.rb'
|
|
84
|
-
|
|
85
|
-
# It can be useful to violate this cop in tests when testing methods that accept a block
|
|
86
|
-
Lint/EmptyBlock:
|
|
87
|
-
Exclude:
|
|
88
|
-
- 'test/**/*.rb'
|
|
89
|
-
|
|
90
|
-
# There are a mix of styles in the tests and so I don't think it's worth enforcing for now
|
|
91
|
-
Naming/VariableNumber:
|
|
92
|
-
Exclude:
|
|
93
|
-
- 'test/**/*.rb'
|
|
94
|
-
|
|
95
|
-
# These methods from Ruby core are legitimately overridden in the tests
|
|
96
|
-
Style/OptionalBooleanParameter:
|
|
97
|
-
AllowedMethods:
|
|
98
|
-
- respond_to?
|
|
99
|
-
- public_methods
|
|
100
|
-
- protected_methods
|
|
101
|
-
- private_methods
|
|
102
|
-
- public_instance_methods
|
|
103
|
-
- protected_instance_methods
|
|
104
|
-
- private_instance_methods
|
|
105
|
-
|
|
106
75
|
# This cop is useful for required environment variables, but not for optional ones
|
|
107
76
|
Style/FetchEnvVar:
|
|
108
77
|
AllowedVars:
|
|
@@ -110,9 +79,6 @@ Style/FetchEnvVar:
|
|
|
110
79
|
|
|
111
80
|
Naming/FileName:
|
|
112
81
|
ExpectMatchingDefinition: true
|
|
113
|
-
CheckDefinitionPathHierarchyRoots:
|
|
114
|
-
- test/unit
|
|
115
|
-
- test/acceptance
|
|
116
82
|
Exclude:
|
|
117
83
|
- lib/mocha/version.rb
|
|
118
84
|
- lib/mocha/minitest.rb
|
|
@@ -120,3 +86,7 @@ Naming/FileName:
|
|
|
120
86
|
- lib/mocha/ruby_version.rb
|
|
121
87
|
- lib/mocha/macos_version.rb
|
|
122
88
|
- test/test_helper.rb
|
|
89
|
+
|
|
90
|
+
Metrics/BlockLength:
|
|
91
|
+
Exclude:
|
|
92
|
+
- "Rakefile"
|
data/.yardopts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
--output-dir docs
|
|
2
2
|
--no-private
|
|
3
|
+
lib/mocha.rb
|
|
3
4
|
lib/mocha/api.rb
|
|
4
5
|
lib/mocha/hooks.rb
|
|
5
6
|
lib/mocha/mock.rb
|
|
@@ -15,6 +16,7 @@ lib/mocha/expectation_error_factory.rb
|
|
|
15
16
|
lib/mocha/expectation_error.rb
|
|
16
17
|
lib/mocha/stubbing_error.rb
|
|
17
18
|
lib/mocha/unexpected_invocation.rb
|
|
19
|
+
lib/mocha/integration.rb
|
|
18
20
|
lib/mocha/integration/test_unit/adapter.rb
|
|
19
21
|
lib/mocha/integration/minitest/adapter.rb
|
|
20
22
|
-
|
data/Gemfile
CHANGED
|
@@ -3,16 +3,13 @@ source 'https://rubygems.org'
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
5
|
group :development do
|
|
6
|
+
gem 'benchmark'
|
|
6
7
|
gem 'introspection', '~> 0.0.1'
|
|
7
8
|
gem 'minitest'
|
|
8
9
|
gem 'rake'
|
|
9
10
|
|
|
10
|
-
if RUBY_ENGINE == 'jruby'
|
|
11
|
-
# Workaround for https://github.com/jruby/jruby/issues/8488
|
|
12
|
-
gem 'jar-dependencies', '~> 0.4.1'
|
|
13
|
-
end
|
|
14
|
-
|
|
15
11
|
if ENV['MOCHA_GENERATE_DOCS']
|
|
12
|
+
gem 'rdoc'
|
|
16
13
|
gem 'redcarpet'
|
|
17
14
|
gem 'yard'
|
|
18
15
|
end
|
data/RELEASE.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## 3.0.0-rc.2
|
|
4
|
+
|
|
5
|
+
### External changes
|
|
6
|
+
|
|
7
|
+
* Fix compatibility with Ruby 3.5 (#755) - thanks to @Earlopain
|
|
8
|
+
* Add missing quotes to docs for `Mocha::ParameterMatchers::Methods#equivalent_uri` (#757) - thanks to @bensherman
|
|
9
|
+
* Increment assertion count on never expected invocation (#763 & #764)
|
|
10
|
+
* Remove deprecated `ParameterMatchers::Base` class; include `ParameterMatchers::BaseMethods` module instead (415ae768)
|
|
11
|
+
* Remove deprecated `ParameterMatcher` methods now available in `ParameterMatcher::Methods` (8de49979)
|
|
12
|
+
* Removed deprecated access to `ParameterMatcher` classes (6ea9e3f5)
|
|
13
|
+
|
|
14
|
+
### Internal changes
|
|
15
|
+
|
|
16
|
+
* Remove workaround for JRuby jar-dependencies issue (#737)
|
|
17
|
+
* Add benchmark to `Gemfile` to fix warning (#733 & #740) - thanks to @nitishr
|
|
18
|
+
* Add documentation coverage check (#707, #743 & #745) - thanks to @nitishr
|
|
19
|
+
* Fix `Lint/LiteralAsCondition` violation (#746) - thanks to @nitishr
|
|
20
|
+
* Fix rdoc-related warning when running doc rake task (#741 & #747)
|
|
21
|
+
* Fail fast in CI builds on any Ruby warnings (#729 & #741) - thanks to @nitishr
|
|
22
|
+
* Add `ObjectMethods#stubba_respond_to?` and use instead of `Object#respond_to?` (#713, #742 & #750) - thanks to @nitishr
|
|
23
|
+
* Rename `#stubbee` -> `#stubba_object` and `#mock_owner` -> `#stubbee` (#463 & #751) - thanks to @nitishr
|
|
24
|
+
* Fix `enable-frozen-string-literal` in CI build (#752) - thanks to @nitishr
|
|
25
|
+
* Various rubocop fixed (#754 & #756)
|
|
26
|
+
* Fix `Layout/EmptyLinesAfterModuleInclusion` violations (3f683220)
|
|
27
|
+
* Auto-correct `Style/RedundantParentheses` violations (0277a592)
|
|
28
|
+
* Automatically retry failed CI builds (9bbdbc66)
|
|
29
|
+
|
|
3
30
|
## 3.0.0-rc.1
|
|
4
31
|
|
|
5
32
|
### External changes
|
|
@@ -37,6 +64,21 @@ for reporting
|
|
|
37
64
|
* Improvements to keyword argument matching tests (#730)
|
|
38
65
|
* Improvements to keyword argument matcher unit test (#731)
|
|
39
66
|
|
|
67
|
+
## 2.8.0
|
|
68
|
+
|
|
69
|
+
Many thanks to @etiennebarrie for his help in testing v3.0.0 release candidates which led to many of these changes.
|
|
70
|
+
|
|
71
|
+
### External changes
|
|
72
|
+
|
|
73
|
+
* Extract `ParameterMatchers::BaseMethods` module and deprecate inheriting from `ParameterMatchers::Base` class (0ddfbe4b)
|
|
74
|
+
* Move matcher builder methods into `ParameterMatchers::Methods` module and only include that module into `API` (2de41423)
|
|
75
|
+
* Provide deprecated access to matcher builder methods when including `ParameterMatchers` module (299488e1)
|
|
76
|
+
* Provide deprecated access to matcher classes, e.g. `ParameterMatchers::Equals`, from within tests/specs (dcced1b4)
|
|
77
|
+
|
|
78
|
+
### Internal changes
|
|
79
|
+
|
|
80
|
+
* Move `ParameterMatchers#parse_option` -> `HasEntry.parse_option` (9e2a6f66)
|
|
81
|
+
|
|
40
82
|
## 2.7.1
|
|
41
83
|
|
|
42
84
|
### External changes
|
data/Rakefile
CHANGED
|
@@ -25,7 +25,7 @@ task 'test' do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
namespace 'test' do
|
|
28
|
+
namespace 'test' do
|
|
29
29
|
desc 'Run unit tests'
|
|
30
30
|
Rake::TestTask.new('units') do |t|
|
|
31
31
|
t.libs << 'test'
|
|
@@ -123,29 +123,49 @@ end
|
|
|
123
123
|
if ENV['MOCHA_GENERATE_DOCS']
|
|
124
124
|
require 'yard'
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
namespace :docs do
|
|
127
|
+
desc 'Remove generated documentation'
|
|
128
|
+
task :clobber do
|
|
129
|
+
`rm -rf ./docs`
|
|
130
|
+
end
|
|
130
131
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
desc 'Generate documentation'
|
|
133
|
+
YARD::Rake::YardocTask.new(:generate) do |task|
|
|
134
|
+
task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
|
|
135
|
+
end
|
|
135
136
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
desc 'Ensure custom domain remains in place for docs on GitHub Pages'
|
|
138
|
+
task :ensure_cname do
|
|
139
|
+
`git checkout docs/CNAME`
|
|
140
|
+
end
|
|
140
141
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
desc 'Ensure custom JavaScript files remain in place for docs on GitHub Pages'
|
|
143
|
+
task :ensure_js do
|
|
144
|
+
`git checkout docs/js/app.js`
|
|
145
|
+
`git checkout docs/js/jquery.js`
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
desc 'Check documentation coverage'
|
|
149
|
+
task :coverage do
|
|
150
|
+
stats_output = `yard stats --list-undoc`
|
|
151
|
+
puts stats_output
|
|
152
|
+
|
|
153
|
+
match = stats_output.match(/(?<coverage_percentage>\d+\.\d+)% documented/);
|
|
154
|
+
abort 'Error: Could not determine documentation coverage.' unless match
|
|
155
|
+
|
|
156
|
+
coverage_percentage = match[:coverage_percentage].to_f
|
|
157
|
+
minimum_percentage = 100.0
|
|
158
|
+
|
|
159
|
+
if coverage_percentage < minimum_percentage
|
|
160
|
+
abort "Documentation coverage is #{coverage_percentage}%, which is below the required #{minimum_percentage}%."
|
|
161
|
+
else
|
|
162
|
+
puts "Documentation coverage is #{coverage_percentage}%, which is at or above the required #{minimum_percentage}%."
|
|
163
|
+
end
|
|
164
|
+
end
|
|
145
165
|
end
|
|
146
166
|
|
|
147
|
-
desc '
|
|
148
|
-
task '
|
|
167
|
+
desc 'Prepare documentation for publication on GitHub Pages'
|
|
168
|
+
task 'docs' => %w[docs:clobber docs:generate docs:ensure_cname docs:ensure_js]
|
|
149
169
|
end
|
|
150
170
|
|
|
151
171
|
task 'release' => ['default', 'rubygems:release']
|
|
@@ -6,16 +6,16 @@ module Mocha
|
|
|
6
6
|
class AnyInstanceMethod < StubbedMethod
|
|
7
7
|
private
|
|
8
8
|
|
|
9
|
-
def
|
|
10
|
-
|
|
9
|
+
def stubbee
|
|
10
|
+
stubba_object.any_instance
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def stubbee_method(method_name)
|
|
14
|
-
|
|
14
|
+
stubba_object.instance_method(method_name)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def original_method_owner
|
|
18
|
-
|
|
18
|
+
stubba_object
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
data/lib/mocha/api.rb
CHANGED
data/lib/mocha/class_methods.rb
CHANGED
|
@@ -28,8 +28,8 @@ module Mocha
|
|
|
28
28
|
@stubba_object
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def
|
|
32
|
-
@stubba_object.allocate.respond_to?(symbol.to_sym
|
|
31
|
+
def stubba_respond_to?(symbol)
|
|
32
|
+
@stubba_object.allocate.respond_to?(symbol.to_sym)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
attr_reader :stubba_object
|
|
@@ -54,9 +54,13 @@ module Mocha
|
|
|
54
54
|
|
|
55
55
|
# @private
|
|
56
56
|
def __method_visibility__(method, include_public_methods: true)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
if include_public_methods && public_method_defined?(method)
|
|
58
|
+
:public
|
|
59
|
+
elsif protected_method_defined?(method)
|
|
60
|
+
:protected
|
|
61
|
+
else
|
|
62
|
+
private_method_defined?(method) ? :private : nil
|
|
63
|
+
end
|
|
60
64
|
end
|
|
61
65
|
alias_method :__method_exists__?, :__method_visibility__
|
|
62
66
|
end
|
data/lib/mocha/configuration.rb
CHANGED
|
@@ -235,7 +235,7 @@ module Mocha
|
|
|
235
235
|
#
|
|
236
236
|
# For more details on keyword arguments in Ruby v3, refer to {https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0 this article}.
|
|
237
237
|
#
|
|
238
|
-
# Note that +Hash+-related matchers such as {ParameterMatchers#has_value} or {ParameterMatchers#has_key} will still treat a positional +Hash+ and a set of keyword arguments the same, so misleading passing tests are still possible when they are used.
|
|
238
|
+
# Note that +Hash+-related matchers such as {ParameterMatchers::Methods#has_value} or {ParameterMatchers::Methods#has_key} will still treat a positional +Hash+ and a set of keyword arguments the same, so misleading passing tests are still possible when they are used.
|
|
239
239
|
#
|
|
240
240
|
# This configuration option is +false+ by default in Ruby v2.7 to enable gradual adoption, but +true+ by default in Ruby >= v3.0.
|
|
241
241
|
#
|
data/lib/mocha/deprecation.rb
CHANGED
data/lib/mocha/expectation.rb
CHANGED
|
@@ -221,7 +221,7 @@ module Mocha
|
|
|
221
221
|
|
|
222
222
|
# Modifies expectation so that the expected method must be called with +expected_parameters_or_matchers+.
|
|
223
223
|
#
|
|
224
|
-
# May be used with Ruby literals or variables for exact matching or with parameter matchers for less-specific matching, e.g. {ParameterMatchers#includes}, {ParameterMatchers#has_key}, etc. See {ParameterMatchers} for a list of all available parameter matchers.
|
|
224
|
+
# May be used with Ruby literals or variables for exact matching or with parameter matchers for less-specific matching, e.g. {ParameterMatchers::Methods#includes}, {ParameterMatchers::Methods#has_key}, etc. See {ParameterMatchers} for a list of all available parameter matchers.
|
|
225
225
|
#
|
|
226
226
|
# Alternatively a block argument can be passed to {#with} to implement custom parameter matching. The block receives the +*actual_parameters+ as its arguments and should return +true+ if they are acceptable or +false+ otherwise. See the example below where a method is expected to be called with a value divisible by 4.
|
|
227
227
|
# The block argument takes precedence over +expected_parameters_or_matchers+. The block may be called multiple times per invocation of the expected method and so it should be idempotent.
|
|
@@ -237,7 +237,7 @@ module Mocha
|
|
|
237
237
|
# @see ParameterMatchers
|
|
238
238
|
# @see Configuration#strict_keyword_argument_matching=
|
|
239
239
|
#
|
|
240
|
-
# @param [Array<Object,ParameterMatchers::
|
|
240
|
+
# @param [Array<Object,ParameterMatchers::BaseMethods>] expected_parameters_or_matchers expected parameter values or parameter matchers.
|
|
241
241
|
# @yield optional block specifying custom matching.
|
|
242
242
|
# @yieldparam [Array<Object>] actual_parameters parameters with which expected method was invoked.
|
|
243
243
|
# @yieldreturn [Boolean] +true+ if +actual_parameters+ are acceptable; +false+ otherwise.
|
|
@@ -31,7 +31,7 @@ module Mocha
|
|
|
31
31
|
matching_expectations(invocation).detect(&:invocations_never_allowed?)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
def verified?(assertion_counter
|
|
34
|
+
def verified?(assertion_counter)
|
|
35
35
|
@expectations.all? { |expectation| expectation.verified?(assertion_counter) }
|
|
36
36
|
end
|
|
37
37
|
|
data/lib/mocha/hooks.rb
CHANGED
|
@@ -21,8 +21,8 @@ module Mocha
|
|
|
21
21
|
# Prepares Mocha before a test (only for use by authors of test libraries).
|
|
22
22
|
#
|
|
23
23
|
# This method should be called before each individual test starts (including before any "setup" code).
|
|
24
|
-
def mocha_setup
|
|
25
|
-
Mockery.setup
|
|
24
|
+
def mocha_setup(assertion_counter)
|
|
25
|
+
Mockery.setup(assertion_counter)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
# Verifies that all mock expectations have been met (only for use by authors of test libraries).
|
|
@@ -30,8 +30,8 @@ module Mocha
|
|
|
30
30
|
# This is equivalent to a series of "assertions".
|
|
31
31
|
#
|
|
32
32
|
# This method should be called at the end of each individual test, before it has been determined whether or not the test has passed.
|
|
33
|
-
def mocha_verify
|
|
34
|
-
Mockery.verify
|
|
33
|
+
def mocha_verify
|
|
34
|
+
Mockery.verify
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
# Resets Mocha after a test (only for use by authors of test libraries).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Mocha
|
|
2
|
+
# @private
|
|
3
|
+
module IgnoringWarning
|
|
4
|
+
def ignoring_warning(pattern, if_: true)
|
|
5
|
+
return yield unless if_
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
original_warn = Warning.method(:warn)
|
|
9
|
+
Warning.singleton_class.define_method(:warn) do |message|
|
|
10
|
+
original_warn.call(message) unless message =~ pattern
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
yield
|
|
14
|
+
ensure
|
|
15
|
+
Warning.singleton_class.undef_method(:warn)
|
|
16
|
+
Warning.singleton_class.define_method(:warn, original_warn)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -6,16 +6,16 @@ module Mocha
|
|
|
6
6
|
class InstanceMethod < StubbedMethod
|
|
7
7
|
private
|
|
8
8
|
|
|
9
|
-
def
|
|
10
|
-
|
|
9
|
+
def stubbee
|
|
10
|
+
stubba_object
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def stubbee_method(method_name)
|
|
14
|
-
|
|
14
|
+
stubba_object._method(method_name)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def original_method_owner
|
|
18
|
-
|
|
18
|
+
stubba_object.singleton_class
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -6,6 +6,7 @@ require 'mocha/expectation_error_factory'
|
|
|
6
6
|
|
|
7
7
|
module Mocha
|
|
8
8
|
module Integration
|
|
9
|
+
# Contains {Adapter} that integrates Mocha into recent versions of Minitest.
|
|
9
10
|
module Minitest
|
|
10
11
|
# Integrates Mocha into recent versions of Minitest.
|
|
11
12
|
#
|
|
@@ -30,7 +31,8 @@ module Mocha
|
|
|
30
31
|
|
|
31
32
|
# @private
|
|
32
33
|
def before_setup
|
|
33
|
-
|
|
34
|
+
assertion_counter = Integration::AssertionCounter.new(self)
|
|
35
|
+
mocha_setup(assertion_counter)
|
|
34
36
|
super
|
|
35
37
|
end
|
|
36
38
|
|
|
@@ -38,8 +40,7 @@ module Mocha
|
|
|
38
40
|
def before_teardown
|
|
39
41
|
return unless passed?
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
mocha_verify(assertion_counter)
|
|
43
|
+
mocha_verify
|
|
43
44
|
ensure
|
|
44
45
|
super
|
|
45
46
|
end
|
|
@@ -6,6 +6,7 @@ require 'mocha/expectation_error'
|
|
|
6
6
|
|
|
7
7
|
module Mocha
|
|
8
8
|
module Integration
|
|
9
|
+
# Contains {Adapter} that integrates Mocha into recent versions of Test::Unit.
|
|
9
10
|
module TestUnit
|
|
10
11
|
# Integrates Mocha into recent versions of Test::Unit.
|
|
11
12
|
#
|
|
@@ -25,13 +26,15 @@ module Mocha
|
|
|
25
26
|
|
|
26
27
|
# @private
|
|
27
28
|
def self.included(mod)
|
|
28
|
-
mod.setup
|
|
29
|
+
mod.setup before: :prepend do
|
|
30
|
+
assertion_counter = Integration::AssertionCounter.new(self)
|
|
31
|
+
mocha_setup(assertion_counter)
|
|
32
|
+
end
|
|
29
33
|
|
|
30
34
|
mod.exception_handler(:handle_mocha_expectation_error)
|
|
31
35
|
|
|
32
36
|
mod.cleanup after: :append do
|
|
33
|
-
|
|
34
|
-
mocha_verify(assertion_counter)
|
|
37
|
+
mocha_verify
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
mod.teardown :mocha_teardown, after: :append
|
|
@@ -45,7 +48,7 @@ module Mocha
|
|
|
45
48
|
end
|
|
46
49
|
|
|
47
50
|
# @private
|
|
48
|
-
def handle_mocha_expectation_error(exception)
|
|
51
|
+
def handle_mocha_expectation_error(exception) # rubocop:disable Naming/PredicateMethod
|
|
49
52
|
return false unless exception.is_a?(Mocha::ExpectationError)
|
|
50
53
|
|
|
51
54
|
problem_occurred
|
data/lib/mocha/mock.rb
CHANGED
|
@@ -276,8 +276,9 @@ module Mocha
|
|
|
276
276
|
end
|
|
277
277
|
|
|
278
278
|
# @private
|
|
279
|
-
def initialize(mockery, name = nil, receiver = nil)
|
|
279
|
+
def initialize(mockery, assertion_counter, name = nil, receiver = nil)
|
|
280
280
|
@mockery = mockery
|
|
281
|
+
@assertion_counter = assertion_counter
|
|
281
282
|
@name = name || DefaultName.new(self)
|
|
282
283
|
@receiver = receiver || DefaultReceiver.new(self)
|
|
283
284
|
@expectations = ExpectationList.new
|
|
@@ -355,8 +356,8 @@ module Mocha
|
|
|
355
356
|
end
|
|
356
357
|
|
|
357
358
|
# @private
|
|
358
|
-
def __verified__?
|
|
359
|
-
@expectations.verified?(assertion_counter)
|
|
359
|
+
def __verified__?
|
|
360
|
+
@expectations.verified?(@assertion_counter)
|
|
360
361
|
end
|
|
361
362
|
|
|
362
363
|
# @private
|
|
@@ -389,7 +390,10 @@ module Mocha
|
|
|
389
390
|
def raise_unexpected_invocation_error(invocation, matching_expectation)
|
|
390
391
|
if @unexpected_invocation.nil?
|
|
391
392
|
@unexpected_invocation = invocation
|
|
392
|
-
|
|
393
|
+
if matching_expectation
|
|
394
|
+
matching_expectation.invoke(invocation)
|
|
395
|
+
@assertion_counter.increment
|
|
396
|
+
end
|
|
393
397
|
call_description = @unexpected_invocation.call_description
|
|
394
398
|
if matching_expectation && !matching_expectation.in_correct_order?
|
|
395
399
|
call_description += ' invoked out of order'
|
data/lib/mocha/mockery.rb
CHANGED
|
@@ -17,6 +17,10 @@ require 'mocha/expectation_error_factory'
|
|
|
17
17
|
module Mocha
|
|
18
18
|
class Mockery
|
|
19
19
|
class Null < self
|
|
20
|
+
def self.build
|
|
21
|
+
new(nil)
|
|
22
|
+
end
|
|
23
|
+
|
|
20
24
|
def add_mock(*)
|
|
21
25
|
raise_not_initialized_error
|
|
22
26
|
end
|
|
@@ -39,18 +43,18 @@ module Mocha
|
|
|
39
43
|
|
|
40
44
|
class << self
|
|
41
45
|
def instance
|
|
42
|
-
@instances.last || Null.
|
|
46
|
+
@instances.last || Null.build
|
|
43
47
|
end
|
|
44
48
|
|
|
45
|
-
def setup
|
|
49
|
+
def setup(assertion_counter)
|
|
46
50
|
@instances ||= []
|
|
47
|
-
mockery = new
|
|
51
|
+
mockery = new(assertion_counter)
|
|
48
52
|
mockery.logger = instance.logger unless @instances.empty?
|
|
49
53
|
@instances.push(mockery)
|
|
50
54
|
end
|
|
51
55
|
|
|
52
|
-
def verify
|
|
53
|
-
instance.verify
|
|
56
|
+
def verify
|
|
57
|
+
instance.verify
|
|
54
58
|
end
|
|
55
59
|
|
|
56
60
|
def teardown(origin = nil)
|
|
@@ -64,28 +68,32 @@ module Mocha
|
|
|
64
68
|
end
|
|
65
69
|
end
|
|
66
70
|
|
|
71
|
+
def initialize(assertion_counter)
|
|
72
|
+
@assertion_counter = assertion_counter
|
|
73
|
+
end
|
|
74
|
+
|
|
67
75
|
def named_mock(name)
|
|
68
|
-
add_mock(Mock.new(self, Name.new(name)))
|
|
76
|
+
add_mock(Mock.new(self, @assertion_counter, Name.new(name)))
|
|
69
77
|
end
|
|
70
78
|
|
|
71
79
|
def unnamed_mock
|
|
72
|
-
add_mock(Mock.new(self))
|
|
80
|
+
add_mock(Mock.new(self, @assertion_counter))
|
|
73
81
|
end
|
|
74
82
|
|
|
75
83
|
def mock_impersonating(object)
|
|
76
|
-
add_mock(Mock.new(self, ImpersonatingName.new(object), ObjectReceiver.new(object)))
|
|
84
|
+
add_mock(Mock.new(self, @assertion_counter, ImpersonatingName.new(object), ObjectReceiver.new(object)))
|
|
77
85
|
end
|
|
78
86
|
|
|
79
87
|
def mock_impersonating_any_instance_of(klass)
|
|
80
|
-
add_mock(Mock.new(self, ImpersonatingAnyInstanceName.new(klass), AnyInstanceReceiver.new(klass)))
|
|
88
|
+
add_mock(Mock.new(self, @assertion_counter, ImpersonatingAnyInstanceName.new(klass), AnyInstanceReceiver.new(klass)))
|
|
81
89
|
end
|
|
82
90
|
|
|
83
91
|
def new_state_machine(name)
|
|
84
92
|
add_state_machine(StateMachine.new(name))
|
|
85
93
|
end
|
|
86
94
|
|
|
87
|
-
def verify
|
|
88
|
-
unless mocks.all?
|
|
95
|
+
def verify
|
|
96
|
+
unless mocks.all?(&:__verified__?)
|
|
89
97
|
message = "not all expectations were satisfied\n#{mocha_inspect}"
|
|
90
98
|
backtrace = if unsatisfied_expectations.empty?
|
|
91
99
|
caller
|
|
@@ -133,7 +141,7 @@ module Mocha
|
|
|
133
141
|
def on_stubbing(object, method)
|
|
134
142
|
signature_proc = lambda { "#{object.mocha_inspect}.#{method}" }
|
|
135
143
|
check(:stubbing_non_existent_method, 'non-existent method', signature_proc) do
|
|
136
|
-
!(object.stubba_class.__method_exists__?(method) || object.
|
|
144
|
+
!(object.stubba_class.__method_exists__?(method) || object.stubba_respond_to?(method))
|
|
137
145
|
end
|
|
138
146
|
check(:stubbing_non_public_method, 'non-public method', signature_proc) do
|
|
139
147
|
object.stubba_class.__method_exists__?(method, include_public_methods: false)
|