verified_double 0.5.3 → 0.6
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/CHANGELOG.markdown +5 -0
- data/Guardfile +1 -1
- data/README.md +12 -2
- data/features/CHANGELOG.markdown +5 -0
- data/features/partial_mocks.feature +162 -0
- data/features/readme.md +12 -2
- data/features/step_definitions/verified_double_steps.rb +4 -0
- data/lib/verified_double.rb +13 -2
- data/lib/verified_double/simple_double.rb +1 -1
- data/lib/verified_double/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6bfd029b36750aeb01fc1a6d0176f58a7d3c623
|
4
|
+
data.tar.gz: aace4f64cbafacac1d051939faa93a6c7c1a1742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90eda38fbddf5d17f03df6f06bbc23e099598564e9329fb6e891d9dfb3516de474352e46f5e4840cf3252ca03082554e6324c38556ad272fb464d745a95315b4
|
7
|
+
data.tar.gz: 9fbae516d65fbafc7f748479c147eb8fb35f62f1a0d450940f397142d007038fc6fc000a6e920c22e70b344a87c99144eea4a4913c56b00d84e219877de992fc
|
data/CHANGELOG.markdown
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -148,9 +148,19 @@ describe Collaborator do
|
|
148
148
|
end
|
149
149
|
```
|
150
150
|
|
151
|
-
## Any Instance mocks
|
151
|
+
## Partial and Any Instance mocks
|
152
152
|
|
153
|
-
Aside for instance and class doubles, VerifiedDouble also supports
|
153
|
+
Aside for instance and class doubles, VerifiedDouble also supports partial and "any instance" mocks:
|
154
|
+
|
155
|
+
```
|
156
|
+
object_under_test = ObjectUnderTest.new
|
157
|
+
|
158
|
+
expect(VerifiedDouble.wrap(object_under_test))
|
159
|
+
.to receive(:some_method).with(input).and_return(output)
|
160
|
+
|
161
|
+
expect(VerifiedDouble.wrap(ObjectUnderTest))
|
162
|
+
.to receive(:some_method).with(input).and_return(output)
|
163
|
+
```
|
154
164
|
|
155
165
|
```
|
156
166
|
VerifiedDouble.expect_any_instance_of(Collaborator)
|
data/features/CHANGELOG.markdown
CHANGED
@@ -0,0 +1,162 @@
|
|
1
|
+
Feature: 65. Partial mocks
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given the following classes:
|
5
|
+
"""
|
6
|
+
class ObjectUnderTest
|
7
|
+
def do_something(input)
|
8
|
+
some_method(input)
|
9
|
+
end
|
10
|
+
|
11
|
+
def some_method(input)
|
12
|
+
SomeOutput.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.do_something(input)
|
16
|
+
some_method(input)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.some_method(input)
|
20
|
+
SomeOutput.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class SomeInput
|
25
|
+
end
|
26
|
+
|
27
|
+
class SomeOutput
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
|
31
|
+
And the test suite is configured to use VerifiedDouble:
|
32
|
+
"""
|
33
|
+
require 'verified_double'
|
34
|
+
require 'verified_double/rspec_configuration'
|
35
|
+
require 'main'
|
36
|
+
"""
|
37
|
+
|
38
|
+
Scenario: Verified partial mocks of instance variables
|
39
|
+
|
40
|
+
Given a test that uses VerifiedDouble to mock the object under test:
|
41
|
+
"""
|
42
|
+
require 'spec_helper'
|
43
|
+
describe ObjectUnderTest do
|
44
|
+
let(:input) { SomeInput.new }
|
45
|
+
let(:output) { SomeOutput.new }
|
46
|
+
|
47
|
+
it "tests something" do
|
48
|
+
object_under_test = ObjectUnderTest.new
|
49
|
+
expect(VerifiedDouble.wrap(object_under_test))
|
50
|
+
.to receive(:some_method).with(input).and_return(output)
|
51
|
+
|
52
|
+
object_under_test.do_something(input)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
"""
|
56
|
+
|
57
|
+
And the test suite has a contract test for the mock:
|
58
|
+
"""
|
59
|
+
require 'spec_helper'
|
60
|
+
|
61
|
+
describe ObjectUnderTest do
|
62
|
+
describe '#some_method(SomeInput)=>SomeOutput', verifies_contract: true do
|
63
|
+
it "tests something" do
|
64
|
+
# do nothing
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
"""
|
69
|
+
|
70
|
+
When I run the test suite
|
71
|
+
Then I should not see any output saying the mock is unverified
|
72
|
+
|
73
|
+
Scenario: Unverified partial mocks of instance variables
|
74
|
+
|
75
|
+
Given a test that uses VerifiedDouble to mock the object under test:
|
76
|
+
"""
|
77
|
+
require 'spec_helper'
|
78
|
+
describe ObjectUnderTest do
|
79
|
+
let(:input) { SomeInput.new }
|
80
|
+
let(:output) { SomeOutput.new }
|
81
|
+
|
82
|
+
it "tests something" do
|
83
|
+
object_under_test = ObjectUnderTest.new
|
84
|
+
expect(VerifiedDouble.wrap(object_under_test))
|
85
|
+
.to receive(:some_method).with(input).and_return(output)
|
86
|
+
|
87
|
+
object_under_test.do_something(input)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
"""
|
91
|
+
|
92
|
+
And the test suite does not have a contract test for the mock
|
93
|
+
|
94
|
+
When I run the test suite
|
95
|
+
Then I should be informed that the stub is unverified:
|
96
|
+
"""
|
97
|
+
The following mocks are not verified:
|
98
|
+
|
99
|
+
1. ObjectUnderTest#some_method(SomeInput)=>SomeOutput
|
100
|
+
"""
|
101
|
+
|
102
|
+
Scenario: Verified partial mocks of class variables
|
103
|
+
|
104
|
+
Given a test that uses VerifiedDouble to mock the object under test:
|
105
|
+
"""
|
106
|
+
require 'spec_helper'
|
107
|
+
describe ObjectUnderTest do
|
108
|
+
let(:input) { SomeInput.new }
|
109
|
+
let(:output) { SomeOutput.new }
|
110
|
+
|
111
|
+
it "tests something" do
|
112
|
+
expect(VerifiedDouble.wrap(ObjectUnderTest))
|
113
|
+
.to receive(:some_method).with(input).and_return(output)
|
114
|
+
|
115
|
+
ObjectUnderTest.do_something(input)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
"""
|
119
|
+
|
120
|
+
And the test suite has a contract test for the mock:
|
121
|
+
"""
|
122
|
+
require 'spec_helper'
|
123
|
+
|
124
|
+
describe ObjectUnderTest do
|
125
|
+
describe '.some_method(SomeInput)=>SomeOutput', verifies_contract: true do
|
126
|
+
it "tests something" do
|
127
|
+
# do nothing
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
"""
|
132
|
+
|
133
|
+
When I run the test suite
|
134
|
+
Then I should not see any output saying the mock is unverified
|
135
|
+
|
136
|
+
Scenario: Unverified partial mocks of class variables
|
137
|
+
|
138
|
+
Given a test that uses VerifiedDouble to mock the object under test:
|
139
|
+
"""
|
140
|
+
require 'spec_helper'
|
141
|
+
describe ObjectUnderTest do
|
142
|
+
let(:input) { SomeInput.new }
|
143
|
+
let(:output) { SomeOutput.new }
|
144
|
+
|
145
|
+
it "tests something" do
|
146
|
+
expect(VerifiedDouble.wrap(ObjectUnderTest))
|
147
|
+
.to receive(:some_method).with(input).and_return(output)
|
148
|
+
|
149
|
+
ObjectUnderTest.do_something(input)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
"""
|
153
|
+
|
154
|
+
And the test suite does not have a contract test for the mock
|
155
|
+
|
156
|
+
When I run the test suite
|
157
|
+
Then I should be informed that the stub is unverified:
|
158
|
+
"""
|
159
|
+
The following mocks are not verified:
|
160
|
+
|
161
|
+
1. ObjectUnderTest.some_method(SomeInput)=>SomeOutput
|
162
|
+
"""
|
data/features/readme.md
CHANGED
@@ -148,9 +148,19 @@ describe Collaborator do
|
|
148
148
|
end
|
149
149
|
```
|
150
150
|
|
151
|
-
## Any Instance mocks
|
151
|
+
## Partial and Any Instance mocks
|
152
152
|
|
153
|
-
Aside for instance and class doubles, VerifiedDouble also supports
|
153
|
+
Aside for instance and class doubles, VerifiedDouble also supports partial and "any instance" mocks:
|
154
|
+
|
155
|
+
```
|
156
|
+
object_under_test = ObjectUnderTest.new
|
157
|
+
|
158
|
+
expect(VerifiedDouble.wrap(object_under_test))
|
159
|
+
.to receive(:some_method).with(input).and_return(output)
|
160
|
+
|
161
|
+
expect(VerifiedDouble.wrap(ObjectUnderTest))
|
162
|
+
.to receive(:some_method).with(input).and_return(output)
|
163
|
+
```
|
154
164
|
|
155
165
|
```
|
156
166
|
VerifiedDouble.expect_any_instance_of(Collaborator)
|
@@ -10,6 +10,10 @@ Given(/^a test that uses VerifiedDouble to mock any instance of the class:$/) do
|
|
10
10
|
write_file 'spec/main_spec.rb', string
|
11
11
|
end
|
12
12
|
|
13
|
+
Given /^a test that uses VerifiedDouble to mock the object under test:$/ do |string|
|
14
|
+
write_file 'spec/main_spec.rb', string
|
15
|
+
end
|
16
|
+
|
13
17
|
Given /^a test that uses VerifiedDouble to stub an object:$/ do |string|
|
14
18
|
write_file 'spec/main_spec.rb', string
|
15
19
|
end
|
data/lib/verified_double.rb
CHANGED
@@ -37,7 +37,9 @@ module VerifiedDouble
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.of_class(class_value, options = {})
|
40
|
-
|
40
|
+
if options[:transfer_nested_constants].nil?
|
41
|
+
options[:transfer_nested_constants] = true
|
42
|
+
end
|
41
43
|
d = stub_const(class_value.to_s, Class.new, options)
|
42
44
|
d.extend(VerifiedDouble::IsAClassDouble)
|
43
45
|
VerifiedDouble.record(d)
|
@@ -81,5 +83,14 @@ module VerifiedDouble
|
|
81
83
|
def self.verified_signatures_from_matchers
|
82
84
|
@verified_signatures_from_matchers ||= []
|
83
85
|
end
|
84
|
-
end
|
85
86
|
|
87
|
+
def self.wrap(object)
|
88
|
+
if object.is_a?(Module)
|
89
|
+
object.extend(VerifiedDouble::IsAClassDouble)
|
90
|
+
else
|
91
|
+
object.extend(VerifiedDouble::IsAnInstanceDouble)
|
92
|
+
end
|
93
|
+
|
94
|
+
VerifiedDouble.record(object)
|
95
|
+
end
|
96
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verified_double
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Mendoza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- features/any_instance.feature
|
158
158
|
- features/customizing_arguments_and_return_values.feature
|
159
159
|
- features/describe_contract.feature
|
160
|
+
- features/partial_mocks.feature
|
160
161
|
- features/readme.md
|
161
162
|
- features/rspec_mock_compatibility.feature
|
162
163
|
- features/step_definitions/verified_double_steps.rb
|
@@ -235,6 +236,7 @@ test_files:
|
|
235
236
|
- features/any_instance.feature
|
236
237
|
- features/customizing_arguments_and_return_values.feature
|
237
238
|
- features/describe_contract.feature
|
239
|
+
- features/partial_mocks.feature
|
238
240
|
- features/readme.md
|
239
241
|
- features/rspec_mock_compatibility.feature
|
240
242
|
- features/step_definitions/verified_double_steps.rb
|