surrogate 0.8.0 → 0.8.1
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 +13 -5
- data/Gemfile +3 -0
- data/Rakefile +11 -12
- data/Readme.md +14 -14
- data/Readme.md.mountain_berry_fields +14 -14
- data/lib/surrogate/rspec/with_filter.rb +1 -2
- data/lib/surrogate/values.rb +13 -1
- data/lib/surrogate/version.rb +1 -1
- data/spec/defining_api_methods_spec.rb +18 -1
- data/todo +12 -0
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDNiZGViOTMzZmVjMTkzMDIzNmU5NDVjMGU2NDAzNjc4MzE5ZjAxYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjlkYzRhNTJmODcyODU0OGI0ZDQ4YjMzYTFhZDZjMWZmYTJmYmRkMg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmI0NjdlZGE4NDA3Yjk5Mjc2YjE4NzU2ZDcyNTQ2MTVkMDQxZTFiYjcyYzA5
|
10
|
+
OWJmMmQ0MzYwYjM0ODE3YzI2NDBkZGQ4ODJmNmQ3M2EwZGFhM2FjYTc2YmY4
|
11
|
+
NDkyNTk4MDQ0MTg1OTkyOWViN2IzYTAxM2Q5M2RmMWM0MTlhZGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDA1NWY0ZThhYmFmMGY1ZjY4ZDkzYWVhYWM4MGY3ZDdlY2ZmZjhkMzlmZjUx
|
14
|
+
NGM3Njg4Y2EyMmVlNmM1ZGQyZDBmYzhiNWQ5Y2Q4Y2VlNjMxNjY3YjFjZjQ0
|
15
|
+
NTI0MWIyMjVmYmNiYWRmYTRmODRiYWRkOGEzYWIzM2FjOThkOTM=
|
data/Gemfile
CHANGED
@@ -1,2 +1,5 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
|
+
gem "mountain_berry_fields", git: 'https://github.com/JoshCheek/mountain_berry_fields.git'
|
4
|
+
gem "mountain_berry_fields-rspec", git: 'https://github.com/JoshCheek/mountain_berry_fields-rspec.git'
|
5
|
+
gem "mountain_berry_fields-magic_comments", git: 'https://github.com/JoshCheek/mountain_berry_fields-magic_comments.git'
|
data/Rakefile
CHANGED
@@ -1,16 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/setup'
|
2
2
|
|
3
|
-
require 'rspec/core/rake_task'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
'--colour',
|
9
|
-
'--format', 'documentation',
|
10
|
-
]
|
4
|
+
desc 'Run specs'
|
5
|
+
task :spec do
|
6
|
+
sh 'rspec --fail-fast --colour --format documentation'
|
11
7
|
end
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
desc 'Test/generate readme'
|
10
|
+
task :readme do
|
11
|
+
sh 'bundle exec mountain_berry_fields Readme.md.mountain_berry_fields'
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
task default: [:spec, :readme]
|
data/Readme.md
CHANGED
@@ -190,7 +190,7 @@ user_class.was told_to :find
|
|
190
190
|
MockUser.was_not told_to :find
|
191
191
|
|
192
192
|
# initializing the clone
|
193
|
-
MockUser.clone(find: nil).find.
|
193
|
+
expect(MockUser.clone(find: nil).find).to be_nil
|
194
194
|
```
|
195
195
|
|
196
196
|
**Mass initialize** with `.factory(key: value)`, this can be turned off by passing
|
@@ -337,7 +337,7 @@ class MockUser
|
|
337
337
|
define :id
|
338
338
|
end
|
339
339
|
user = MockUser.new 12
|
340
|
-
user.id.
|
340
|
+
expect(user.id).to eq 12
|
341
341
|
user.was initialized_with 12
|
342
342
|
```
|
343
343
|
|
@@ -354,9 +354,9 @@ class MockUser
|
|
354
354
|
end
|
355
355
|
|
356
356
|
user = MockUser.new
|
357
|
-
user.
|
357
|
+
expect(user).to_not be_admin
|
358
358
|
user.will_have_admin? true
|
359
|
-
user.
|
359
|
+
expect(user).to be_admin
|
360
360
|
user.was asked_if(:admin?).times(2)
|
361
361
|
```
|
362
362
|
|
@@ -390,25 +390,25 @@ class MockUser
|
|
390
390
|
end
|
391
391
|
|
392
392
|
# they are the same
|
393
|
-
User.
|
393
|
+
expect(User).to substitute_for MockUser
|
394
394
|
|
395
395
|
# they differ
|
396
396
|
MockUser.define :name
|
397
|
-
User.
|
397
|
+
expect(User).to_not substitute_for MockUser
|
398
398
|
|
399
399
|
# signatures don't match (you can turn this off by passing `types: false` to substitute_for)
|
400
400
|
class UserWithWrongSignature
|
401
401
|
def initialize()end # no id
|
402
402
|
def id()end
|
403
403
|
end
|
404
|
-
UserWithWrongSignature.
|
404
|
+
expect(UserWithWrongSignature).to_not substitute_for MockUser
|
405
405
|
|
406
406
|
# parameter names don't match
|
407
407
|
class UserWithWrongParamNames
|
408
408
|
def initialize(name)end # real one takes an id
|
409
409
|
def id()end
|
410
410
|
end
|
411
|
-
UserWithWrongParamNames.
|
411
|
+
expect(UserWithWrongParamNames).to_not substitute_for MockUser, names: true
|
412
412
|
```
|
413
413
|
|
414
414
|
Sometimes you don't want to have to implement the entire interface.
|
@@ -429,11 +429,11 @@ class MockUser
|
|
429
429
|
end
|
430
430
|
|
431
431
|
# doesn't matter that real user has a name as long as it has initialize and id
|
432
|
-
User.
|
432
|
+
expect(User).to substitute_for MockUser, subset: true
|
433
433
|
|
434
434
|
# but now it fails b/c it has no address
|
435
435
|
MockUser.define :address
|
436
|
-
User.
|
436
|
+
expect(User).to_not substitute_for MockUser, subset: true
|
437
437
|
```
|
438
438
|
|
439
439
|
|
@@ -467,10 +467,10 @@ describe 'something that creates a user through the service' do
|
|
467
467
|
end
|
468
468
|
|
469
469
|
service.was told_to(:create).with { |block|
|
470
|
-
block.call_with({id: new_id})
|
471
|
-
block.returns old_id
|
472
|
-
block.before { user_id.
|
473
|
-
block.after { user_id.
|
470
|
+
block.call_with({id: new_id}) # this will be given to the block
|
471
|
+
block.returns old_id # provide a return value, or a block that receives the return value (where you can make assertions)
|
472
|
+
block.before { expect(user_id).to eq old_id } # assertions about state of the world before the block is called
|
473
|
+
block.after { expect(user_id).to eq new_id } # assertions about the state of the world after the block is called
|
474
474
|
}
|
475
475
|
end
|
476
476
|
end
|
@@ -223,7 +223,7 @@ user_class.was told_to :find
|
|
223
223
|
MockUser.was_not told_to :find
|
224
224
|
|
225
225
|
# initializing the clone
|
226
|
-
MockUser.clone(find: nil).find.
|
226
|
+
expect(MockUser.clone(find: nil).find).to be_nil
|
227
227
|
<% end %>
|
228
228
|
```
|
229
229
|
|
@@ -422,7 +422,7 @@ class MockUser
|
|
422
422
|
define :id
|
423
423
|
end
|
424
424
|
user = MockUser.new 12
|
425
|
-
user.id.
|
425
|
+
expect(user.id).to eq 12
|
426
426
|
user.was initialized_with 12
|
427
427
|
<% end %>
|
428
428
|
```
|
@@ -441,9 +441,9 @@ class MockUser
|
|
441
441
|
end
|
442
442
|
|
443
443
|
user = MockUser.new
|
444
|
-
user.
|
444
|
+
expect(user).to_not be_admin
|
445
445
|
user.will_have_admin? true
|
446
|
-
user.
|
446
|
+
expect(user).to be_admin
|
447
447
|
user.was asked_if(:admin?).times(2)
|
448
448
|
<% end %>
|
449
449
|
```
|
@@ -479,25 +479,25 @@ class MockUser
|
|
479
479
|
end
|
480
480
|
|
481
481
|
# they are the same
|
482
|
-
User.
|
482
|
+
expect(User).to substitute_for MockUser
|
483
483
|
|
484
484
|
# they differ
|
485
485
|
MockUser.define :name
|
486
|
-
User.
|
486
|
+
expect(User).to_not substitute_for MockUser
|
487
487
|
|
488
488
|
# signatures don't match (you can turn this off by passing `types: false` to substitute_for)
|
489
489
|
class UserWithWrongSignature
|
490
490
|
def initialize()end # no id
|
491
491
|
def id()end
|
492
492
|
end
|
493
|
-
UserWithWrongSignature.
|
493
|
+
expect(UserWithWrongSignature).to_not substitute_for MockUser
|
494
494
|
|
495
495
|
# parameter names don't match
|
496
496
|
class UserWithWrongParamNames
|
497
497
|
def initialize(name)end # real one takes an id
|
498
498
|
def id()end
|
499
499
|
end
|
500
|
-
UserWithWrongParamNames.
|
500
|
+
expect(UserWithWrongParamNames).to_not substitute_for MockUser, names: true
|
501
501
|
<% end %>
|
502
502
|
```
|
503
503
|
|
@@ -520,11 +520,11 @@ class MockUser
|
|
520
520
|
end
|
521
521
|
|
522
522
|
# doesn't matter that real user has a name as long as it has initialize and id
|
523
|
-
User.
|
523
|
+
expect(User).to substitute_for MockUser, subset: true
|
524
524
|
|
525
525
|
# but now it fails b/c it has no address
|
526
526
|
MockUser.define :address
|
527
|
-
User.
|
527
|
+
expect(User).to_not substitute_for MockUser, subset: true
|
528
528
|
<% end %>
|
529
529
|
```
|
530
530
|
|
@@ -560,10 +560,10 @@ describe 'something that creates a user through the service' do
|
|
560
560
|
end
|
561
561
|
|
562
562
|
service.was told_to(:create).with { |block|
|
563
|
-
block.call_with({id: new_id})
|
564
|
-
block.returns old_id
|
565
|
-
block.before { user_id.
|
566
|
-
block.after { user_id.
|
563
|
+
block.call_with({id: new_id}) # this will be given to the block
|
564
|
+
block.returns old_id # provide a return value, or a block that receives the return value (where you can make assertions)
|
565
|
+
block.before { expect(user_id).to eq old_id } # assertions about state of the world before the block is called
|
566
|
+
block.after { expect(user_id).to eq new_id } # assertions about the state of the world after the block is called
|
567
567
|
}
|
568
568
|
end
|
569
569
|
end
|
data/lib/surrogate/values.rb
CHANGED
@@ -6,7 +6,9 @@ class Surrogate
|
|
6
6
|
# convert raw arguments into a value
|
7
7
|
def self.factory(*args, &block)
|
8
8
|
arg = args.first
|
9
|
-
if
|
9
|
+
if block
|
10
|
+
BlockValue.new &block
|
11
|
+
elsif args.size > 1
|
10
12
|
ValueQueue.new args
|
11
13
|
elsif arg.kind_of? Exception
|
12
14
|
Raisable.new arg
|
@@ -34,6 +36,16 @@ class Surrogate
|
|
34
36
|
end
|
35
37
|
|
36
38
|
|
39
|
+
class BlockValue < BaseValue
|
40
|
+
def initialize(&block)
|
41
|
+
@block = block
|
42
|
+
end
|
43
|
+
|
44
|
+
def value(method_name)
|
45
|
+
@block.call
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
37
49
|
class Raisable < BaseValue
|
38
50
|
def value(*)
|
39
51
|
raise @value
|
data/lib/surrogate/version.rb
CHANGED
@@ -60,6 +60,9 @@ describe 'define' do
|
|
60
60
|
before { mocked_class.define :wink }
|
61
61
|
|
62
62
|
describe 'will_<api_method>' do
|
63
|
+
it 'returns the object' do
|
64
|
+
instance.will_wink(:quickly).should equal instance
|
65
|
+
end
|
63
66
|
it 'overrides the default value for the api method' do
|
64
67
|
mock1 = mocked_class.new
|
65
68
|
mock2 = mocked_class.new
|
@@ -69,9 +72,23 @@ describe 'define' do
|
|
69
72
|
mock2.wink.should == :slowly
|
70
73
|
mock1.wink.should == :quickly
|
71
74
|
end
|
75
|
+
end
|
72
76
|
|
77
|
+
describe 'will_<api_method> { ... }' do
|
73
78
|
it 'returns the object' do
|
74
|
-
instance.will_wink(:quickly).should equal instance
|
79
|
+
instance.will_wink(:quickly) { }.should equal instance
|
80
|
+
end
|
81
|
+
it 'overrides the default behaviour for the api method' do
|
82
|
+
mock1 = mocked_class.new
|
83
|
+
mock2 = mocked_class.new
|
84
|
+
winks = []
|
85
|
+
mock1.will_wink { winks << 1 }
|
86
|
+
mock2.will_wink { winks << 2 }
|
87
|
+
|
88
|
+
winks.should == []
|
89
|
+
expect(mock1.wink).to eq [1]
|
90
|
+
expect(mock2.wink).to eq [1, 2]
|
91
|
+
expect(mock1.wink).to eq [1, 2, 1]
|
75
92
|
end
|
76
93
|
end
|
77
94
|
|
data/todo
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
Surrogate
|
2
|
+
get a reflector
|
3
|
+
block matcher: if it *was* told to write beforehand, then tell me fucking where
|
4
|
+
record callers
|
5
|
+
when capturing a block, can opt to invoke immediately, if later make assertions against that block, and they fail, also notify user that it was previously invoked (e.g. before conditions may be false)
|
6
|
+
all arguments must be explicit
|
7
|
+
rspec: expect(surrogate).was told_to...
|
8
|
+
get rid of initialized_with matcher
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
1
13
|
Urgent (things I want to do immediately, formatted as the git commits I will use)
|
2
14
|
---------------------------------------------------------------------------------
|
3
15
|
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surrogate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Cheek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
description: Framework to aid in handrolling mock/spy objects.
|
@@ -45,8 +45,8 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
-
|
49
|
-
-
|
48
|
+
- .gitignore
|
49
|
+
- .travis.yml
|
50
50
|
- Changelog.md
|
51
51
|
- Gemfile
|
52
52
|
- Rakefile
|
@@ -102,17 +102,17 @@ require_paths:
|
|
102
102
|
- lib
|
103
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- -
|
105
|
+
- - ! '>='
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - ! '>='
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project: surrogate
|
115
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.4.1
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Framework to aid in handrolling mock/spy objects.
|