mocha 1.13.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile +29 -0
- data/README.md +2 -2
- data/RELEASE.md +33 -0
- data/Rakefile +7 -13
- data/gemfiles/Gemfile.minitest.latest +1 -0
- data/gemfiles/Gemfile.test-unit.latest +2 -5
- data/lib/mocha/any_instance_method.rb +0 -5
- data/lib/mocha/api.rb +24 -13
- data/lib/mocha/class_methods.rb +2 -2
- data/lib/mocha/instance_method.rb +0 -4
- data/lib/mocha/integration/test_unit.rb +0 -2
- data/lib/mocha/invocation.rb +11 -2
- data/lib/mocha/minitest.rb +1 -0
- data/lib/mocha/mock.rb +13 -17
- data/lib/mocha/mockery.rb +1 -3
- data/lib/mocha/ruby_version.rb +8 -1
- data/lib/mocha/stubbed_method.rb +3 -4
- data/lib/mocha/test_unit.rb +1 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha.rb +0 -8
- data/mocha.gemspec +2 -33
- metadata +8 -66
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +0 -61
- data/lib/mocha/singleton_class.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6be1c2dafee7237e2ff675159cbc86afd1b5a56493d2671eba64cc4fbb001dd
|
4
|
+
data.tar.gz: 2bde2824fd9b2f5a3ba6445f9f3e42e1e97053f235eb5fea647410f037a0cee2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd3c082fca1dd5123b1c7ac6dd65ba4c9a2e92ec8791dcbc6f3d4a9a9f9c8161cf8cf4b9058c7483f5419118cdfea6cfc17cc0b206964dfc98ed8271852ea5ee
|
7
|
+
data.tar.gz: 074fcc5048dd385eb929c03b5757c517eaceb0f72e8536500d867b3571f072a7aa29afc8a7a78a4ab0db3c7208a5c811c0a5754d30b9ebaec213ea1337f17eea
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 1.
|
4
|
+
TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 1.9'
|
5
5
|
|
6
6
|
# Even the reference in the documentation suggests that you should prefer
|
7
7
|
# `alias_method` vs `alias`, so I don't understand why that isn't the default.
|
data/Gemfile
CHANGED
@@ -1,3 +1,32 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
|
+
|
5
|
+
# rubocop:disable Bundler/DuplicatedGem
|
6
|
+
if RUBY_VERSION < '2'
|
7
|
+
gem 'rake', '~> 12.2.1'
|
8
|
+
elsif RUBY_VERSION < '2.2'
|
9
|
+
gem 'rake', '~> 12.3.3'
|
10
|
+
else
|
11
|
+
gem 'rake'
|
12
|
+
end
|
13
|
+
# rubocop:enable Bundler/DuplicatedGem
|
14
|
+
|
15
|
+
gem 'introspection', '~> 0.0.1'
|
16
|
+
|
17
|
+
# Avoid breaking change in psych v4 (https://bugs.ruby-lang.org/issues/17866)
|
18
|
+
if RUBY_VERSION >= '3.1.0'
|
19
|
+
gem 'psych', '< 4'
|
20
|
+
end
|
21
|
+
|
22
|
+
if RUBY_VERSION >= '2.2.0'
|
23
|
+
# No test libraries in standard library
|
24
|
+
gem 'minitest'
|
25
|
+
end
|
26
|
+
if RUBY_VERSION >= '2.2.0'
|
27
|
+
gem 'rubocop', '<= 0.58.2'
|
28
|
+
end
|
29
|
+
if ENV['MOCHA_GENERATE_DOCS']
|
30
|
+
gem 'redcarpet'
|
31
|
+
gem 'yard'
|
32
|
+
end
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
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)
|
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)
|
2
2
|
|
3
3
|
### Description
|
4
4
|
|
@@ -338,7 +338,7 @@ $ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-625523-7 rake gen
|
|
338
338
|
* Sign in to rubygems.org and find API key - https://rubygems.org/profile/edit
|
339
339
|
|
340
340
|
```bash
|
341
|
-
$ curl -u
|
341
|
+
$ curl -u <email-address> -H 'OTP:<one-time-password>' https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials
|
342
342
|
```
|
343
343
|
|
344
344
|
* Release gem to Rubygems:
|
data/RELEASE.md
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
# Release Notes
|
2
2
|
|
3
|
+
## 1.15.0
|
4
|
+
|
5
|
+
### External changes
|
6
|
+
|
7
|
+
* Fix examples using mock constructor with block (1cc17667)
|
8
|
+
* Add another example for `API#sequence` (b7a7d233, #59)
|
9
|
+
* Remove support for Ruby v1.8 (ddb5d672)
|
10
|
+
* Deprecate support for Ruby versions earlier than v2.0 - thanks to @wasabigeek (#553, #555)
|
11
|
+
|
12
|
+
### Internal changes
|
13
|
+
|
14
|
+
* Update instructions for obtaining Rubygems API key (ed9c040a)
|
15
|
+
* Consistent definitions for `respond_to?` methods (#533)
|
16
|
+
* Run test tasks before release tasks (92a1bc6e, #447)
|
17
|
+
* Fix test:performance Rake task (#538, #539)
|
18
|
+
* Tidying following removal of support for Ruby v1.8 - thanks to @nitishr (#542)
|
19
|
+
* Remove `ParametersMatcher` from `Invocation#call_description` - thanks to @wasabigeek (#543)
|
20
|
+
* Remove unnecessary splatting in Invocation - thanks to @wasabigeek (#549)
|
21
|
+
* Extract `handle_method_call` from `method_missing` - thanks to @wasabigeek (#550)
|
22
|
+
|
23
|
+
## 1.14.0
|
24
|
+
|
25
|
+
### External changes
|
26
|
+
|
27
|
+
* Mock#expects,#stubs should return last expectation - thanks to @vlad-pisanov for #524 (b6b637db)
|
28
|
+
|
29
|
+
### Internal changes
|
30
|
+
|
31
|
+
* Avoid breaking change in psych v4 in ruby v3.1 (08b9f4ca)
|
32
|
+
* Remove broken Dependabot badge from README (d446657a)
|
33
|
+
* Add Ruby 3.0 to the CI matrix - thanks to @mishina2228 for #526 (65bc626e)
|
34
|
+
* Move development dependencies from gemspec to Gemfile - thanks to @mishina2228 for #527 (dd127f7b)
|
35
|
+
|
3
36
|
## 1.13.0
|
4
37
|
|
5
38
|
### External changes
|
data/Rakefile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'bundler'
|
2
|
-
|
2
|
+
namespace 'rubygems' do
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
end
|
3
5
|
require 'bundler/setup'
|
4
6
|
|
5
7
|
require 'rake/testtask'
|
@@ -18,15 +20,10 @@ task 'test' do
|
|
18
20
|
end
|
19
21
|
|
20
22
|
namespace 'test' do # rubocop:disable Metrics/BlockLength
|
21
|
-
unit_tests = FileList['test/unit/**/*_test.rb']
|
22
|
-
all_acceptance_tests = FileList['test/acceptance/*_test.rb']
|
23
|
-
ruby186_incompatible_acceptance_tests = FileList['test/acceptance/stub_class_method_defined_on_*_test.rb'] + FileList['test/acceptance/stub_instance_method_defined_on_*_test.rb']
|
24
|
-
ruby186_compatible_acceptance_tests = all_acceptance_tests - ruby186_incompatible_acceptance_tests
|
25
|
-
|
26
23
|
desc 'Run unit tests'
|
27
24
|
Rake::TestTask.new('units') do |t|
|
28
25
|
t.libs << 'test'
|
29
|
-
t.test_files =
|
26
|
+
t.test_files = FileList['test/unit/**/*_test.rb']
|
30
27
|
t.verbose = true
|
31
28
|
t.warning = true
|
32
29
|
end
|
@@ -34,11 +31,7 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength
|
|
34
31
|
desc 'Run acceptance tests'
|
35
32
|
Rake::TestTask.new('acceptance') do |t|
|
36
33
|
t.libs << 'test'
|
37
|
-
t.test_files =
|
38
|
-
all_acceptance_tests
|
39
|
-
else
|
40
|
-
ruby186_compatible_acceptance_tests
|
41
|
-
end
|
34
|
+
t.test_files = FileList['test/acceptance/*_test.rb']
|
42
35
|
t.verbose = true
|
43
36
|
t.warning = true
|
44
37
|
end
|
@@ -100,6 +93,7 @@ def benchmark_test_case(klass, iterations)
|
|
100
93
|
if defined?(MiniTest)
|
101
94
|
minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version)
|
102
95
|
if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version)
|
96
|
+
Minitest.seed = 1
|
103
97
|
result = Benchmark.realtime { iterations.times { |_i| klass.run(MiniTest::CompositeReporter.new) } }
|
104
98
|
MiniTest::Runnable.runnables.delete(klass)
|
105
99
|
result
|
@@ -154,4 +148,4 @@ if ENV['MOCHA_GENERATE_DOCS']
|
|
154
148
|
task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
|
155
149
|
end
|
156
150
|
|
157
|
-
task 'release' => 'default'
|
151
|
+
task 'release' => ['default', 'rubygems:release']
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'mocha/ruby_version'
|
2
1
|
require 'mocha/stubbed_method'
|
3
2
|
|
4
3
|
module Mocha
|
@@ -9,10 +8,6 @@ module Mocha
|
|
9
8
|
stubbee.any_instance
|
10
9
|
end
|
11
10
|
|
12
|
-
def method_body(method)
|
13
|
-
method
|
14
|
-
end
|
15
|
-
|
16
11
|
def stubbee_method(method_name)
|
17
12
|
stubbee.instance_method(method_name)
|
18
13
|
end
|
data/lib/mocha/api.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'mocha/ruby_version'
|
1
2
|
require 'mocha/parameter_matchers'
|
2
3
|
require 'mocha/hooks'
|
3
4
|
require 'mocha/mockery'
|
@@ -199,11 +200,22 @@ module Mocha
|
|
199
200
|
# @example Ensure methods on egg are invoked in correct order.
|
200
201
|
# breakfast = sequence('breakfast')
|
201
202
|
#
|
202
|
-
# egg = mock('egg')
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
#
|
203
|
+
# egg = mock('egg')
|
204
|
+
# egg.expects(:crack).in_sequence(breakfast)
|
205
|
+
# egg.expects(:fry).in_sequence(breakfast)
|
206
|
+
# egg.expects(:eat).in_sequence(breakfast)
|
207
|
+
#
|
208
|
+
# @example Ensure methods across multiple objects are invoked in correct order.
|
209
|
+
# sequence = sequence(:task_order)
|
210
|
+
#
|
211
|
+
# task_one = mock("task_one")
|
212
|
+
# task_two = mock("task_two")
|
213
|
+
#
|
214
|
+
# task_one.expects(:execute).in_sequence(sequence)
|
215
|
+
# task_two.expects(:execute).in_sequence(sequence)
|
216
|
+
#
|
217
|
+
# task_one.execute
|
218
|
+
# task_two.execute
|
207
219
|
def sequence(name)
|
208
220
|
Sequence.new(name)
|
209
221
|
end
|
@@ -226,14 +238,13 @@ module Mocha
|
|
226
238
|
# @example Constrain expected invocations to occur in particular states.
|
227
239
|
# power = states('power').starts_as('off')
|
228
240
|
#
|
229
|
-
# radio = mock('radio')
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
# end
|
241
|
+
# radio = mock('radio')
|
242
|
+
# radio.expects(:switch_on).then(power.is('on'))
|
243
|
+
# radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on'))
|
244
|
+
# radio.expects(:adjust_volume).with(+5).when(power.is('on'))
|
245
|
+
# radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
|
246
|
+
# radio.expects(:adjust_volume).with(-5).when(power.is('on'))
|
247
|
+
# radio.expects(:switch_off).then(power.is('off'))
|
237
248
|
def states(name)
|
238
249
|
Mockery.instance.new_state_machine(name)
|
239
250
|
end
|
data/lib/mocha/class_methods.rb
CHANGED
@@ -26,8 +26,8 @@ module Mocha
|
|
26
26
|
@stubba_object
|
27
27
|
end
|
28
28
|
|
29
|
-
def respond_to?(
|
30
|
-
@stubba_object.allocate.respond_to?(
|
29
|
+
def respond_to?(symbol, include_all = false)
|
30
|
+
@stubba_object.allocate.respond_to?(symbol.to_sym, include_all)
|
31
31
|
end
|
32
32
|
|
33
33
|
attr_reader :stubba_object
|
@@ -3,7 +3,6 @@ require 'mocha/debug'
|
|
3
3
|
require 'mocha/detection/test_unit'
|
4
4
|
|
5
5
|
require 'mocha/integration/test_unit/nothing'
|
6
|
-
require 'mocha/integration/test_unit/ruby_version_185_and_below'
|
7
6
|
require 'mocha/integration/test_unit/ruby_version_186_and_above'
|
8
7
|
require 'mocha/integration/test_unit/gem_version_200'
|
9
8
|
require 'mocha/integration/test_unit/gem_version_201_to_202'
|
@@ -31,7 +30,6 @@ module Mocha
|
|
31
30
|
TestUnit::GemVersion201To202,
|
32
31
|
TestUnit::GemVersion200,
|
33
32
|
TestUnit::RubyVersion186AndAbove,
|
34
|
-
TestUnit::RubyVersion185AndBelow,
|
35
33
|
TestUnit::Nothing
|
36
34
|
].detect { |m| m.applicable_to?(test_unit_version, ruby_version) }
|
37
35
|
|
data/lib/mocha/invocation.rb
CHANGED
@@ -10,7 +10,7 @@ module Mocha
|
|
10
10
|
class Invocation
|
11
11
|
attr_reader :method_name, :block
|
12
12
|
|
13
|
-
def initialize(mock, method_name,
|
13
|
+
def initialize(mock, method_name, arguments = [], block = nil)
|
14
14
|
@mock = mock
|
15
15
|
@method_name = method_name
|
16
16
|
@arguments = arguments
|
@@ -55,7 +55,7 @@ module Mocha
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def call_description
|
58
|
-
description = "#{@mock.mocha_inspect}.#{@method_name}#{
|
58
|
+
description = "#{@mock.mocha_inspect}.#{@method_name}#{argument_description}"
|
59
59
|
description << ' { ... }' unless @block.nil?
|
60
60
|
description
|
61
61
|
end
|
@@ -73,5 +73,14 @@ module Mocha
|
|
73
73
|
def full_description
|
74
74
|
"\n - #{call_description} #{result_description}"
|
75
75
|
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def argument_description
|
80
|
+
signature = arguments.mocha_inspect
|
81
|
+
signature = signature.gsub(/^\[|\]$/, '')
|
82
|
+
signature = signature.gsub(/^\{|\}$/, '') if arguments.length == 1
|
83
|
+
"(#{signature})"
|
84
|
+
end
|
76
85
|
end
|
77
86
|
end
|
data/lib/mocha/minitest.rb
CHANGED
data/lib/mocha/mock.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'mocha/singleton_class'
|
2
1
|
require 'mocha/expectation'
|
3
2
|
require 'mocha/expectation_list'
|
4
3
|
require 'mocha/invocation'
|
@@ -8,7 +7,6 @@ require 'mocha/method_matcher'
|
|
8
7
|
require 'mocha/parameters_matcher'
|
9
8
|
require 'mocha/argument_iterator'
|
10
9
|
require 'mocha/expectation_error_factory'
|
11
|
-
require 'mocha/ruby_version'
|
12
10
|
|
13
11
|
module Mocha
|
14
12
|
# Traditional mock object.
|
@@ -109,6 +107,7 @@ module Mocha
|
|
109
107
|
# object.expects(:expected_method_one).returns(:result_one)
|
110
108
|
# object.expects(:expected_method_two).returns(:result_two)
|
111
109
|
def expects(method_name_or_hash, backtrace = nil)
|
110
|
+
expectation = nil
|
112
111
|
iterator = ArgumentIterator.new(method_name_or_hash)
|
113
112
|
iterator.each do |*args|
|
114
113
|
method_name = args.shift
|
@@ -117,6 +116,7 @@ module Mocha
|
|
117
116
|
expectation.returns(args.shift) unless args.empty?
|
118
117
|
@expectations.add(expectation)
|
119
118
|
end
|
119
|
+
expectation
|
120
120
|
end
|
121
121
|
|
122
122
|
# Adds an expectation that the specified method may be called any number of times with any parameters.
|
@@ -145,6 +145,7 @@ module Mocha
|
|
145
145
|
# object.stubs(:stubbed_method_one).returns(:result_one)
|
146
146
|
# object.stubs(:stubbed_method_two).returns(:result_two)
|
147
147
|
def stubs(method_name_or_hash, backtrace = nil)
|
148
|
+
expectation = nil
|
148
149
|
iterator = ArgumentIterator.new(method_name_or_hash)
|
149
150
|
iterator.each do |*args|
|
150
151
|
method_name = args.shift
|
@@ -154,6 +155,7 @@ module Mocha
|
|
154
155
|
expectation.returns(args.shift) unless args.empty?
|
155
156
|
@expectations.add(expectation)
|
156
157
|
end
|
158
|
+
expectation
|
157
159
|
end
|
158
160
|
|
159
161
|
# Removes the specified stubbed methods (added by calls to {#expects} or {#stubs}) and all expectations associated with them.
|
@@ -161,7 +163,7 @@ module Mocha
|
|
161
163
|
# @param [Array<Symbol>] method_names names of methods to unstub.
|
162
164
|
#
|
163
165
|
# @example Invoking an unstubbed method causes error to be raised
|
164
|
-
# object = mock('mock')
|
166
|
+
# object = mock('mock')
|
165
167
|
# object.stubs(:stubbed_method).returns(:result_one)
|
166
168
|
# object.stubbed_method # => :result_one
|
167
169
|
# object.unstub(:stubbed_method)
|
@@ -307,9 +309,14 @@ module Mocha
|
|
307
309
|
|
308
310
|
# @private
|
309
311
|
def method_missing(symbol, *arguments, &block) # rubocop:disable Style/MethodMissingSuper
|
312
|
+
handle_method_call(symbol, arguments, block)
|
313
|
+
end
|
314
|
+
|
315
|
+
# @private
|
316
|
+
def handle_method_call(symbol, arguments, block)
|
310
317
|
check_expiry
|
311
318
|
check_responder_responds_to(symbol)
|
312
|
-
invocation = Invocation.new(self, symbol,
|
319
|
+
invocation = Invocation.new(self, symbol, arguments, block)
|
313
320
|
if (matching_expectation_allowing_invocation = all_expectations.match_allowing_invocation(invocation))
|
314
321
|
matching_expectation_allowing_invocation.invoke(invocation)
|
315
322
|
elsif (matching_expectation = all_expectations.match(invocation)) || (!matching_expectation && !@everything_stubbed)
|
@@ -318,25 +325,14 @@ module Mocha
|
|
318
325
|
end
|
319
326
|
|
320
327
|
# @private
|
321
|
-
def respond_to_missing?(symbol,
|
328
|
+
def respond_to_missing?(symbol, include_all)
|
322
329
|
if @responder
|
323
|
-
|
324
|
-
@responder.respond_to?(symbol, include_private)
|
325
|
-
else
|
326
|
-
@responder.respond_to?(symbol)
|
327
|
-
end
|
330
|
+
@responder.respond_to?(symbol, include_all)
|
328
331
|
else
|
329
332
|
@everything_stubbed || all_expectations.matches_method?(symbol)
|
330
333
|
end
|
331
334
|
end
|
332
335
|
|
333
|
-
if PRE_RUBY_V19
|
334
|
-
# @private
|
335
|
-
def respond_to?(symbol, include_private = false)
|
336
|
-
respond_to_missing?(symbol, include_private)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
336
|
# @private
|
341
337
|
def __verified__?(assertion_counter = nil)
|
342
338
|
@expectations.verified?(assertion_counter)
|
data/lib/mocha/mockery.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'mocha/ruby_version'
|
2
1
|
require 'mocha/central'
|
3
2
|
require 'mocha/mock'
|
4
3
|
require 'mocha/names'
|
@@ -119,10 +118,9 @@ module Mocha
|
|
119
118
|
end
|
120
119
|
|
121
120
|
def on_stubbing(object, method)
|
122
|
-
method = PRE_RUBY_V19 ? method.to_s : method.to_sym
|
123
121
|
signature_proc = lambda { "#{object.mocha_inspect}.#{method}" }
|
124
122
|
check(:stubbing_non_existent_method, 'non-existent method', signature_proc) do
|
125
|
-
!(object.stubba_class.__method_exists__?(method, true) || object.respond_to?(method
|
123
|
+
!(object.stubba_class.__method_exists__?(method, true) || object.respond_to?(method))
|
126
124
|
end
|
127
125
|
check(:stubbing_non_public_method, 'non-public method', signature_proc) do
|
128
126
|
object.stubba_class.__method_exists__?(method, false)
|
data/lib/mocha/ruby_version.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
+
require 'mocha/deprecation'
|
2
|
+
|
1
3
|
module Mocha
|
2
|
-
PRE_RUBY_V19 = Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9')
|
3
4
|
RUBY_V2_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2')
|
5
|
+
|
6
|
+
unless RUBY_V2_PLUS
|
7
|
+
Mocha::Deprecation.warning(
|
8
|
+
'Versions of Ruby earlier than v2.0 will not be supported in future versions of Mocha.'
|
9
|
+
)
|
10
|
+
end
|
4
11
|
end
|
data/lib/mocha/stubbed_method.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'mocha/ruby_version'
|
2
|
-
require 'mocha/singleton_class'
|
3
2
|
|
4
3
|
module Mocha
|
5
4
|
class StubbedMethod
|
@@ -11,7 +10,7 @@ module Mocha
|
|
11
10
|
@stubbee = stubbee
|
12
11
|
@original_method = nil
|
13
12
|
@original_visibility = nil
|
14
|
-
@method_name =
|
13
|
+
@method_name = method_name.to_sym
|
15
14
|
end
|
16
15
|
|
17
16
|
def stub
|
@@ -58,7 +57,7 @@ module Mocha
|
|
58
57
|
self_in_scope = self
|
59
58
|
method_name_in_scope = method_name
|
60
59
|
stub_method_owner.send(:define_method, method_name) do |*args, &block|
|
61
|
-
self_in_scope.mock.
|
60
|
+
self_in_scope.mock.handle_method_call(method_name_in_scope, args, block)
|
62
61
|
end
|
63
62
|
retain_original_visibility(stub_method_owner)
|
64
63
|
end
|
@@ -74,7 +73,7 @@ module Mocha
|
|
74
73
|
def restore_original_method
|
75
74
|
return if use_prepended_module_for_stub_method?
|
76
75
|
if stub_method_overwrites_original_method?
|
77
|
-
original_method_owner.send(:define_method, method_name,
|
76
|
+
original_method_owner.send(:define_method, method_name, @original_method)
|
78
77
|
end
|
79
78
|
retain_original_visibility(original_method_owner)
|
80
79
|
end
|
data/lib/mocha/test_unit.rb
CHANGED
data/lib/mocha/version.rb
CHANGED
data/lib/mocha.rb
CHANGED
data/mocha.gemspec
CHANGED
@@ -2,11 +2,11 @@ lib = File.expand_path('../lib/', __FILE__)
|
|
2
2
|
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'mocha/version'
|
4
4
|
|
5
|
-
Gem::Specification.new do |s|
|
5
|
+
Gem::Specification.new do |s|
|
6
6
|
s.name = 'mocha'
|
7
7
|
s.version = Mocha::VERSION
|
8
8
|
s.licenses = ['MIT', 'BSD-2-Clause']
|
9
|
-
s.required_ruby_version = '>= 1.
|
9
|
+
s.required_ruby_version = '>= 1.9'
|
10
10
|
|
11
11
|
s.authors = ['James Mead']
|
12
12
|
s.description = 'Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.'
|
@@ -21,35 +21,4 @@ Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength
|
|
21
21
|
s.homepage = 'https://mocha.jamesmead.org'
|
22
22
|
s.require_paths = ['lib']
|
23
23
|
s.summary = 'Mocking and stubbing library'
|
24
|
-
|
25
|
-
unless s.respond_to?(:add_development_dependency)
|
26
|
-
class << s
|
27
|
-
def add_development_dependency(*args)
|
28
|
-
add_dependency(*args)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
if RUBY_VERSION < '1.9.3'
|
34
|
-
s.add_development_dependency 'rake', '~> 10.0'
|
35
|
-
elsif RUBY_VERSION < '2'
|
36
|
-
s.add_development_dependency 'rake', '~> 12.2.1'
|
37
|
-
elsif RUBY_VERSION < '2.2'
|
38
|
-
s.add_development_dependency 'rake', '~> 12.3.3'
|
39
|
-
else
|
40
|
-
s.add_development_dependency 'rake'
|
41
|
-
end
|
42
|
-
|
43
|
-
s.add_development_dependency('introspection', '~> 0.0.1')
|
44
|
-
if RUBY_VERSION >= '2.2.0'
|
45
|
-
# No test libraries in standard library
|
46
|
-
s.add_development_dependency('minitest')
|
47
|
-
end
|
48
|
-
if RUBY_VERSION >= '2.2.0'
|
49
|
-
s.add_development_dependency('rubocop', '<= 0.58.2')
|
50
|
-
end
|
51
|
-
if ENV['MOCHA_GENERATE_DOCS']
|
52
|
-
s.add_development_dependency('redcarpet')
|
53
|
-
s.add_development_dependency('yard')
|
54
|
-
end
|
55
24
|
end
|
metadata
CHANGED
@@ -1,71 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mocha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Mead
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: introspection
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.1
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.0.1
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "<="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.58.2
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "<="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.58.2
|
11
|
+
date: 2022-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
69
13
|
description: Mocking and stubbing library with JMock/SchMock syntax, which allows
|
70
14
|
mocking and stubbing of methods on real (non-mock) classes.
|
71
15
|
email: mocha-developer@googlegroups.com
|
@@ -136,7 +80,6 @@ files:
|
|
136
80
|
- lib/mocha/integration/test_unit/gem_version_203_to_220.rb
|
137
81
|
- lib/mocha/integration/test_unit/gem_version_230_to_250.rb
|
138
82
|
- lib/mocha/integration/test_unit/nothing.rb
|
139
|
-
- lib/mocha/integration/test_unit/ruby_version_185_and_below.rb
|
140
83
|
- lib/mocha/integration/test_unit/ruby_version_186_and_above.rb
|
141
84
|
- lib/mocha/invocation.rb
|
142
85
|
- lib/mocha/is_a.rb
|
@@ -180,7 +123,6 @@ files:
|
|
180
123
|
- lib/mocha/sequence.rb
|
181
124
|
- lib/mocha/setup.rb
|
182
125
|
- lib/mocha/single_return_value.rb
|
183
|
-
- lib/mocha/singleton_class.rb
|
184
126
|
- lib/mocha/state_machine.rb
|
185
127
|
- lib/mocha/stubbed_method.rb
|
186
128
|
- lib/mocha/stubbing_error.rb
|
@@ -197,7 +139,7 @@ licenses:
|
|
197
139
|
- MIT
|
198
140
|
- BSD-2-Clause
|
199
141
|
metadata: {}
|
200
|
-
post_install_message:
|
142
|
+
post_install_message:
|
201
143
|
rdoc_options: []
|
202
144
|
require_paths:
|
203
145
|
- lib
|
@@ -205,15 +147,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
147
|
requirements:
|
206
148
|
- - ">="
|
207
149
|
- !ruby/object:Gem::Version
|
208
|
-
version: 1.
|
150
|
+
version: '1.9'
|
209
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
152
|
requirements:
|
211
153
|
- - ">="
|
212
154
|
- !ruby/object:Gem::Version
|
213
155
|
version: '0'
|
214
156
|
requirements: []
|
215
|
-
rubygems_version: 3.
|
216
|
-
signing_key:
|
157
|
+
rubygems_version: 3.1.6
|
158
|
+
signing_key:
|
217
159
|
specification_version: 4
|
218
160
|
summary: Mocking and stubbing library
|
219
161
|
test_files: []
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'mocha/integration/assertion_counter'
|
2
|
-
require 'mocha/integration/monkey_patcher'
|
3
|
-
require 'mocha/expectation_error'
|
4
|
-
|
5
|
-
module Mocha
|
6
|
-
module Integration
|
7
|
-
module TestUnit
|
8
|
-
module RubyVersion185AndBelow
|
9
|
-
def self.applicable_to?(test_unit_version, ruby_version)
|
10
|
-
Gem::Requirement.new('<= 1.2.3').satisfied_by?(test_unit_version) && Gem::Requirement.new('<= 1.8.5').satisfied_by?(ruby_version)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.description
|
14
|
-
'monkey patch for standard library in Ruby <= v1.8.5'
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.included(mod)
|
18
|
-
MonkeyPatcher.apply(mod, RunMethodPatch)
|
19
|
-
end
|
20
|
-
|
21
|
-
module RunMethodPatch
|
22
|
-
# rubocop:disable all
|
23
|
-
def run(result)
|
24
|
-
assertion_counter = AssertionCounter.new(self)
|
25
|
-
yield(Test::Unit::TestCase::STARTED, name)
|
26
|
-
@_result = result
|
27
|
-
begin
|
28
|
-
begin
|
29
|
-
mocha_setup
|
30
|
-
setup
|
31
|
-
__send__(@method_name)
|
32
|
-
mocha_verify(assertion_counter)
|
33
|
-
rescue Mocha::ExpectationError => e
|
34
|
-
add_failure(e.message, e.backtrace)
|
35
|
-
rescue Test::Unit::AssertionFailedError => e
|
36
|
-
add_failure(e.message, e.backtrace)
|
37
|
-
rescue StandardError, ScriptError
|
38
|
-
add_error($!)
|
39
|
-
ensure
|
40
|
-
begin
|
41
|
-
teardown
|
42
|
-
rescue Mocha::ExpectationError => e
|
43
|
-
add_failure(e.message, e.backtrace)
|
44
|
-
rescue Test::Unit::AssertionFailedError => e
|
45
|
-
add_failure(e.message, e.backtrace)
|
46
|
-
rescue StandardError, ScriptError
|
47
|
-
add_error($!)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
ensure
|
51
|
-
mocha_teardown
|
52
|
-
end
|
53
|
-
result.add_run
|
54
|
-
yield(Test::Unit::TestCase::FINISHED, name)
|
55
|
-
end
|
56
|
-
# rubocop:enable all
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|