surrogate 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +4 -0
- data/lib/surrogate.rb +0 -2
- data/lib/surrogate/endower.rb +1 -1
- data/lib/surrogate/hatchling.rb +1 -3
- data/lib/surrogate/method_definition.rb +2 -2
- data/lib/surrogate/version.rb +1 -1
- data/spec/acceptance_spec.rb +0 -4
- data/spec/defining_api_methods_spec.rb +5 -4
- data/spec/rspec/substitute_for_spec.rb +17 -5
- metadata +12 -12
data/Changelog.md
CHANGED
data/lib/surrogate.rb
CHANGED
data/lib/surrogate/endower.rb
CHANGED
@@ -78,11 +78,11 @@ class Surrogate
|
|
78
78
|
|
79
79
|
def enable_defining_methods(klass)
|
80
80
|
def klass.define(method_name, options={}, &block)
|
81
|
+
block ||= lambda {}
|
81
82
|
@hatchery.define method_name.to_sym, options, &block
|
82
83
|
end
|
83
84
|
|
84
85
|
def klass.define_reader(*method_names, &block)
|
85
|
-
block ||= lambda {}
|
86
86
|
method_names.each { |method_name| define method_name, &block }
|
87
87
|
self
|
88
88
|
end
|
data/lib/surrogate/hatchling.rb
CHANGED
@@ -53,9 +53,7 @@ class Surrogate
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def get_default(method_name, invocation)
|
56
|
-
api_methods[method_name].default instance, invocation
|
57
|
-
raise UnpreparedMethodError, "#{method_name} has been invoked without being told how to behave"
|
58
|
-
end
|
56
|
+
api_methods[method_name].default instance, invocation
|
59
57
|
end
|
60
58
|
|
61
59
|
def must_know(method_name)
|
@@ -26,13 +26,13 @@ class Surrogate
|
|
26
26
|
default_proc && errorizer.match!(*args)
|
27
27
|
end
|
28
28
|
|
29
|
-
def default(instance, invocation
|
29
|
+
def default(instance, invocation)
|
30
30
|
if options.has_key? :default
|
31
31
|
options[:default]
|
32
32
|
elsif default_proc
|
33
33
|
default_proc_as_method_on(instance).call(*invocation.args, &invocation.block)
|
34
34
|
else
|
35
|
-
|
35
|
+
raise "You should never get here. Please open a issue at http://github.com/JoshCheek/surrogate"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
data/lib/surrogate/version.rb
CHANGED
data/spec/acceptance_spec.rb
CHANGED
@@ -91,10 +91,6 @@ describe Surrogate do
|
|
91
91
|
# defaults are used if provided
|
92
92
|
Mock::User.new(1).name.should == 'Josh'
|
93
93
|
|
94
|
-
# error is raised if you try to access an attribute that hasn't been set and has no default
|
95
|
-
expect { Mock::User.new(1).address }.to raise_error Surrogate::UnpreparedMethodError
|
96
|
-
Mock::User.new(1).will_have_address('123 Fake St.').address.should == '123 Fake St.'
|
97
|
-
|
98
94
|
# methods with multiple args
|
99
95
|
user.phone_numbers.should be_empty
|
100
96
|
user.add_phone_number '123', '456-7890'
|
@@ -183,9 +183,9 @@ describe 'define' do
|
|
183
183
|
mocked_class.new.other_meth(1).should == 2
|
184
184
|
end
|
185
185
|
|
186
|
-
it '
|
186
|
+
it 'returns nil when there is no default block' do
|
187
187
|
mocked_class.define :meth
|
188
|
-
|
188
|
+
instance.meth.should equal nil
|
189
189
|
end
|
190
190
|
|
191
191
|
it 'considers ivars of the same name to be its default when it has no suffix' do
|
@@ -222,11 +222,12 @@ describe 'define' do
|
|
222
222
|
expect { instance.meth "extra", "args" }.to raise_error ArgumentError, /wrong number of arguments \(2 for 0\)/
|
223
223
|
end
|
224
224
|
|
225
|
-
it '
|
225
|
+
it 'treats bastard methods as having no arity' do
|
226
226
|
mocked_class.define :meth
|
227
227
|
mocked = mocked_class.new
|
228
228
|
mocked.instance_variable_set :@meth, "abc"
|
229
|
-
mocked.meth 1, 2, 3
|
229
|
+
expect { mocked.meth 1, 2, 3 }.to raise_error ArgumentError
|
230
|
+
expect { mocked.meth }.to_not raise_error
|
230
231
|
end
|
231
232
|
|
232
233
|
it 'can make #initialize an api method' do
|
@@ -188,10 +188,14 @@ describe 'substutability matchers' do
|
|
188
188
|
klass.should substitute_for surrogate, names: false, types: true
|
189
189
|
end
|
190
190
|
|
191
|
-
it '
|
192
|
-
klass = Class.new { def instance_meth(a) end }
|
191
|
+
it 'treats a bastard method as a no arity method' do
|
193
192
|
surrogate = Surrogate.endow(Class.new).define :instance_meth
|
193
|
+
|
194
|
+
klass = Class.new { def instance_meth() end }
|
194
195
|
klass.should substitute_for surrogate, types: true
|
196
|
+
|
197
|
+
klass = Class.new { def instance_meth(a) end }
|
198
|
+
klass.should_not substitute_for surrogate, types: true
|
195
199
|
end
|
196
200
|
|
197
201
|
it 'disregards when real object has natively implemented methods that cannot be reflected on' do
|
@@ -286,15 +290,23 @@ describe 'substutability matchers' do
|
|
286
290
|
klass.should substitute_for surrogate, types: false, names: true
|
287
291
|
end
|
288
292
|
|
289
|
-
it '
|
293
|
+
it 'treats bastard methods as no arity methods' do
|
290
294
|
# instance
|
291
|
-
klass = Class.new { def instance_meth(a) end }
|
292
295
|
surrogate = Surrogate.endow(Class.new).define(:instance_meth)
|
296
|
+
|
297
|
+
klass = Class.new { def instance_meth(a) end }
|
298
|
+
klass.should_not substitute_for surrogate, names: true
|
299
|
+
|
300
|
+
klass = Class.new { def instance_meth() end }
|
293
301
|
klass.should substitute_for surrogate, names: true
|
294
302
|
|
295
303
|
# class
|
296
|
-
klass = Class.new { def self.class_meth(a) end }
|
297
304
|
surrogate = Surrogate.endow(Class.new) { define :class_meth }
|
305
|
+
|
306
|
+
klass = Class.new { def self.class_meth(a) end }
|
307
|
+
klass.should_not substitute_for surrogate, names: true
|
308
|
+
|
309
|
+
klass = Class.new { def self.class_meth() end }
|
298
310
|
klass.should substitute_for surrogate, names: true
|
299
311
|
end
|
300
312
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surrogate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70341864482800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70341864482800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70341864481800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.4'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70341864481800
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mountain_berry_fields
|
38
|
-
requirement: &
|
38
|
+
requirement: &70341864496820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.3
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70341864496820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mountain_berry_fields-rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70341864496280 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.3
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70341864496280
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mountain_berry_fields-magic_comments
|
60
|
-
requirement: &
|
60
|
+
requirement: &70341864495600 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 1.0.1
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70341864495600
|
69
69
|
description: Framework to aid in handrolling mock/spy objects.
|
70
70
|
email:
|
71
71
|
- josh.cheek@gmail.com
|