spy 0.4.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +5 -5
- data/CHANGELOG.md +3 -2
- data/README.md +3 -2
- data/Rakefile +1 -1
- data/lib/spy/subroutine.rb +12 -0
- data/lib/spy/version.rb +1 -1
- data/spy.gemspec +4 -2
- data/test/spy/test_mock.rb +2 -2
- data/test/spy/test_subroutine.rb +36 -4
- data/test/support/pen.rb +15 -5
- data/test/test_helper.rb +2 -0
- metadata +33 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc1c3954f26350a18af51b75fd2400d06600c859ba9e4675a2ddfb5b983f8a8d
|
4
|
+
data.tar.gz: e535c67bdf68ba225c6cfb98f3182c53004de5452e27eb3d3476deaa16369956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d6fb00c5cdc3e0f435f24ffdff53921fa8578f69a004c0b995fda335b69a694a4ea06fe61541d66fb0d40c0a52303d197ceec5b429bec102c09828da19082a4
|
7
|
+
data.tar.gz: 16de7875661311fa5d6ca327ff4510751e88d743e672e937492a8d4abcbd11599f12df9667965c2e5434a5bd6b5725c12caf4c781672fac033ce6c51b5746dbe
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,8 @@
|
|
9
9
|
|
10
10
|
Spy is a lightweight stubbing framework with support for method spies, constant stubs, and object mocks.
|
11
11
|
|
12
|
-
Spy
|
12
|
+
Spy supports ruby 2.1.0+.
|
13
|
+
For versions less than 2.1 use v0.4.5
|
13
14
|
|
14
15
|
Spy features that were completed were tested against the rspec-mocks tests so it covers all cases that rspec-mocks does.
|
15
16
|
|
@@ -197,7 +198,7 @@ In your test file
|
|
197
198
|
```ruby
|
198
199
|
def test_title
|
199
200
|
book = Book.new
|
200
|
-
title_spy = Spy.on(book, title)
|
201
|
+
title_spy = Spy.on(book, :title)
|
201
202
|
book.title
|
202
203
|
book.title
|
203
204
|
|
data/Rakefile
CHANGED
data/lib/spy/subroutine.rb
CHANGED
@@ -32,6 +32,7 @@ module Spy
|
|
32
32
|
def initialize(object, method_name, singleton_method = true)
|
33
33
|
@base_object, @method_name = object, method_name
|
34
34
|
@singleton_method = singleton_method
|
35
|
+
@plan = nil
|
35
36
|
reset!
|
36
37
|
end
|
37
38
|
|
@@ -282,6 +283,8 @@ module Spy
|
|
282
283
|
@arity_range ||=
|
283
284
|
if original_method
|
284
285
|
min = max = 0
|
286
|
+
key_args = false
|
287
|
+
opt_keys = false
|
285
288
|
original_method.parameters.each do |type,_|
|
286
289
|
case type
|
287
290
|
when :req
|
@@ -291,8 +294,17 @@ module Spy
|
|
291
294
|
max += 1
|
292
295
|
when :rest
|
293
296
|
max = Float::INFINITY
|
297
|
+
when :keyreq
|
298
|
+
key_args = true
|
299
|
+
when :keyrest, :key
|
300
|
+
key_args = true
|
301
|
+
opt_keys = true
|
294
302
|
end
|
295
303
|
end
|
304
|
+
if key_args
|
305
|
+
max += 1
|
306
|
+
min += 1 unless opt_keys
|
307
|
+
end
|
296
308
|
(min..max)
|
297
309
|
end
|
298
310
|
end
|
data/lib/spy/version.rb
CHANGED
data/spy.gemspec
CHANGED
@@ -6,12 +6,12 @@ require 'spy/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "spy"
|
8
8
|
gem.version = Spy::VERSION
|
9
|
-
gem.required_ruby_version = '>= 1.
|
9
|
+
gem.required_ruby_version = '>= 2.1.0'
|
10
10
|
gem.license = 'MIT'
|
11
11
|
gem.authors = ["Ryan Ong"]
|
12
12
|
gem.email = ["ryanong@gmail.com"]
|
13
13
|
gem.summary = %q{A simple modern mocking library that uses the spy pattern and checks method's existence and arity.}
|
14
|
-
gem.description = %q{Spy is a mocking library that was made for the modern age. It supports only 1.
|
14
|
+
gem.description = %q{Spy is a mocking library that was made for the modern age. It supports only 2.1.0+. Spy by default will raise an error if you attempt to stub a method that doesn't exist or call the stubbed method with the wrong arity.}
|
15
15
|
gem.homepage = "https://github.com/ryanong/spy"
|
16
16
|
|
17
17
|
gem.files = `git ls-files`.split($/)
|
@@ -20,7 +20,9 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.require_paths = ["lib"]
|
21
21
|
gem.add_development_dependency('pry')
|
22
22
|
gem.add_development_dependency('pry-nav')
|
23
|
+
gem.add_development_dependency('pry-stack_explorer')
|
23
24
|
gem.add_development_dependency('minitest', '>= 4.5.0')
|
25
|
+
gem.add_development_dependency('minitest-reporters')
|
24
26
|
gem.add_development_dependency('rspec-core')
|
25
27
|
gem.add_development_dependency('rspec-expectations')
|
26
28
|
gem.add_development_dependency('coveralls')
|
data/test/spy/test_mock.rb
CHANGED
@@ -68,6 +68,7 @@ module Spy
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
BUGGY_METHODS = %i(tap pretty_print_inspect trust untrust untrusted?)
|
71
72
|
def test_mocked_methods
|
72
73
|
pen_methods = Pen.public_instance_methods(false) +
|
73
74
|
Pen.protected_instance_methods(false) +
|
@@ -76,8 +77,7 @@ module Spy
|
|
76
77
|
assert_equal pen_methods.sort, @pen_mock.mocked_methods.sort
|
77
78
|
end
|
78
79
|
|
79
|
-
|
80
|
-
methods_to_test = Object.instance_methods - buggy_methods
|
80
|
+
methods_to_test = Object.instance_methods - BUGGY_METHODS
|
81
81
|
methods_to_test.each do |method_name|
|
82
82
|
object_method = Object.instance_method(method_name)
|
83
83
|
if object_method.arity == 0 || (RUBY_ENGINE != "jruby" && object_method.parameters == [])
|
data/test/spy/test_subroutine.rb
CHANGED
@@ -40,13 +40,13 @@ module Spy
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_spy_can_hook_and_record_a_meta_method_call_on_a_constant
|
43
|
-
assert_equal "
|
44
|
-
meta_spy = spy_on(Pen, :
|
43
|
+
assert_equal "meta_class_method", Pen.meta_class_method
|
44
|
+
meta_spy = spy_on(Pen, :meta_class_method)
|
45
45
|
refute meta_spy.has_been_called?
|
46
|
-
assert_nil Pen.
|
46
|
+
assert_nil Pen.meta_class_method
|
47
47
|
assert meta_spy.has_been_called?
|
48
48
|
meta_spy.unhook
|
49
|
-
assert_equal "
|
49
|
+
assert_equal "meta_class_method", Pen.meta_class_method
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_spy_can_hook_record_and_unhook_a_meta_method
|
@@ -199,6 +199,38 @@ module Spy
|
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
202
|
+
def test_that_method_spy_keeps_arity_with_optional_keyword_args
|
203
|
+
spy_on(@pen, :opt_kwargs)
|
204
|
+
@pen.opt_kwargs(:pos1)
|
205
|
+
@pen.opt_kwargs(:pos1, opt: 1, opt2: 2)
|
206
|
+
assert_raises ArgumentError do
|
207
|
+
@pen.opt_kwargs
|
208
|
+
end
|
209
|
+
assert_raises ArgumentError do
|
210
|
+
@pen.opt_kwargs(:pos1, :pos2, opt: 1)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_that_method_spy_keeps_arity_with_keyword_splat
|
215
|
+
spy_on(@pen, :keyrest)
|
216
|
+
@pen.keyrest
|
217
|
+
@pen.keyrest(a: 1, b: 2)
|
218
|
+
assert_raises ArgumentError do
|
219
|
+
@pen.keyrest(:pos1, :pos2)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_that_method_spy_keeps_arity_with_required_keyword_args
|
224
|
+
spy_on(@pen, :req_kwargs)
|
225
|
+
@pen.req_kwargs(req1: 1, req2: 2)
|
226
|
+
assert_raises ArgumentError do
|
227
|
+
@pen.req_kwargs
|
228
|
+
end
|
229
|
+
assert_raises ArgumentError do
|
230
|
+
@pen.req_kwargs(:pos1, :pos2)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
202
234
|
def test_hook_mimics_public_visibility
|
203
235
|
spy_on(@pen, :public_method)
|
204
236
|
assert @pen.singleton_class.public_method_defined? :public_method
|
data/test/support/pen.rb
CHANGED
@@ -38,6 +38,18 @@ class Pen
|
|
38
38
|
"another"
|
39
39
|
end
|
40
40
|
|
41
|
+
def opt_kwargs(required, opt: nil, opt2: nil)
|
42
|
+
[required, opt: opt, opt2: opt2]
|
43
|
+
end
|
44
|
+
|
45
|
+
def keyrest(**kwargs)
|
46
|
+
kwargs
|
47
|
+
end
|
48
|
+
|
49
|
+
def req_kwargs(req1:, req2:)
|
50
|
+
[req1, req2]
|
51
|
+
end
|
52
|
+
|
41
53
|
protected
|
42
54
|
def protected_method
|
43
55
|
end
|
@@ -65,13 +77,11 @@ class Pen
|
|
65
77
|
end
|
66
78
|
end
|
67
79
|
|
68
|
-
|
69
|
-
|
70
|
-
Pen.define_singleton_method(:meta_method) do
|
71
|
-
another
|
80
|
+
Pen.define_singleton_method(:meta_class_method) do
|
81
|
+
"meta_class_method".freeze
|
72
82
|
end
|
73
83
|
|
74
84
|
Pen.send(:define_method, :meta_method) do
|
75
|
-
|
85
|
+
"meta_method".freeze
|
76
86
|
end
|
77
87
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Ong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-stack_explorer
|
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'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: minitest
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 4.5.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rspec-core
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +123,7 @@ dependencies:
|
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
125
|
description: Spy is a mocking library that was made for the modern age. It supports
|
98
|
-
only 1.
|
126
|
+
only 2.1.0+. Spy by default will raise an error if you attempt to stub a method
|
99
127
|
that doesn't exist or call the stubbed method with the wrong arity.
|
100
128
|
email:
|
101
129
|
- ryanong@gmail.com
|
@@ -162,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
190
|
requirements:
|
163
191
|
- - ">="
|
164
192
|
- !ruby/object:Gem::Version
|
165
|
-
version: 1.
|
193
|
+
version: 2.1.0
|
166
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
195
|
requirements:
|
168
196
|
- - ">="
|
@@ -170,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
198
|
version: '0'
|
171
199
|
requirements: []
|
172
200
|
rubyforge_project:
|
173
|
-
rubygems_version: 2.
|
201
|
+
rubygems_version: 2.7.6
|
174
202
|
signing_key:
|
175
203
|
specification_version: 4
|
176
204
|
summary: A simple modern mocking library that uses the spy pattern and checks method's
|
@@ -201,4 +229,3 @@ test_files:
|
|
201
229
|
- test/spy/test_subroutine.rb
|
202
230
|
- test/support/pen.rb
|
203
231
|
- test/test_helper.rb
|
204
|
-
has_rdoc:
|