verified_double 0.5.2 → 0.5.3
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/README.md +5 -5
- data/features/CHANGELOG.markdown +5 -0
- data/features/any_instance.feature +63 -4
- data/features/readme.md +5 -5
- data/features/step_definitions/verified_double_steps.rb +13 -0
- data/lib/verified_double/rspec_mocks_syntax_overrides.rb +1 -8
- data/lib/verified_double/simple_double.rb +3 -3
- data/lib/verified_double/version.rb +1 -1
- data/lib/verified_double.rb +10 -5
- data/spec/verified_double/rspec_mocks_syntax_overrides_spec.rb +0 -9
- metadata +1 -2
- data/lib/verified_double/is_an_any_instance_double.rb +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 97ca8fc74d9ad9dddff6b285850a673f46e092f1
|
|
4
|
+
data.tar.gz: 638a65c4724ac5023ba85c717cda05c93bf9fde9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e813041bbf2731d2b2b4f7aae3bb547c1e57cf85181da4422f563e0ad725b3b90841a9fae2d32ae1bc9597f3767077de97202b658e70880596d315c0af5d51db
|
|
7
|
+
data.tar.gz: 3180a6b9822c22912b9117cc993be47ebbfe8770c5bef2e3304a706005f141741b731396598e74528a3f03a4da0243a97d9a593c76a192fcacd35607f462b6bb
|
data/CHANGELOG.markdown
CHANGED
data/README.md
CHANGED
|
@@ -153,12 +153,12 @@ end
|
|
|
153
153
|
Aside for instance and class doubles, VerifiedDouble also supports `any_instance` mocks:
|
|
154
154
|
|
|
155
155
|
```
|
|
156
|
-
VerifiedDouble.
|
|
157
|
-
.
|
|
158
|
-
```
|
|
156
|
+
VerifiedDouble.expect_any_instance_of(Collaborator)
|
|
157
|
+
.to receive(:some_method).with(input).and_return(output)
|
|
159
158
|
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
VerifiedDouble.allow_any_instance_of(Collaborator)
|
|
160
|
+
.to receive(:some_method).with(input).and_return(output)
|
|
161
|
+
```
|
|
162
162
|
|
|
163
163
|
## Complete documentation
|
|
164
164
|
|
data/features/CHANGELOG.markdown
CHANGED
|
@@ -45,8 +45,8 @@ Feature: 60. Any instance
|
|
|
45
45
|
let(:output) { SomeOutput.new }
|
|
46
46
|
|
|
47
47
|
it "tests something" do
|
|
48
|
-
VerifiedDouble.
|
|
49
|
-
.
|
|
48
|
+
VerifiedDouble.expect_any_instance_of(Collaborator)
|
|
49
|
+
.to receive(:some_method).with(input).and_return(output)
|
|
50
50
|
|
|
51
51
|
ObjectUnderTest.new.do_something(Collaborator.new, input)
|
|
52
52
|
end
|
|
@@ -77,8 +77,8 @@ Feature: 60. Any instance
|
|
|
77
77
|
let(:output) { SomeOutput.new }
|
|
78
78
|
|
|
79
79
|
it "tests something" do
|
|
80
|
-
VerifiedDouble.
|
|
81
|
-
.
|
|
80
|
+
VerifiedDouble.expect_any_instance_of(Collaborator)
|
|
81
|
+
.to receive(:some_method).with(input).and_return(output)
|
|
82
82
|
|
|
83
83
|
ObjectUnderTest.new.do_something(Collaborator.new, input)
|
|
84
84
|
end
|
|
@@ -93,3 +93,62 @@ Feature: 60. Any instance
|
|
|
93
93
|
|
|
94
94
|
1. Collaborator#some_method(SomeInput)=>SomeOutput
|
|
95
95
|
"""
|
|
96
|
+
|
|
97
|
+
Scenario: Verify any instance of a class
|
|
98
|
+
|
|
99
|
+
Given a test that uses VerifiedDouble to stub any instance of the class:
|
|
100
|
+
"""
|
|
101
|
+
require 'spec_helper'
|
|
102
|
+
describe ObjectUnderTest do
|
|
103
|
+
let(:input) { SomeInput.new }
|
|
104
|
+
let(:output) { SomeOutput.new }
|
|
105
|
+
|
|
106
|
+
it "tests something" do
|
|
107
|
+
VerifiedDouble.allow_any_instance_of(Collaborator)
|
|
108
|
+
.to receive(:some_method).with(input).and_return(output)
|
|
109
|
+
|
|
110
|
+
ObjectUnderTest.new.do_something(Collaborator.new, input)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
And the test suite has a contract test for the mock:
|
|
116
|
+
"""
|
|
117
|
+
require 'spec_helper'
|
|
118
|
+
|
|
119
|
+
describe 'Collaborator' do
|
|
120
|
+
it "tests something",
|
|
121
|
+
verifies_contract: 'Collaborator#some_method(SomeInput)=>SomeOutput' do
|
|
122
|
+
# do nothing
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
When I run the test suite
|
|
128
|
+
Then I should not see any output saying the stub is unverified
|
|
129
|
+
|
|
130
|
+
Scenario: Unverified any_instance stub
|
|
131
|
+
Given a test that uses VerifiedDouble to stub any instance of the class:
|
|
132
|
+
"""
|
|
133
|
+
require 'spec_helper'
|
|
134
|
+
describe ObjectUnderTest do
|
|
135
|
+
let(:input) { SomeInput.new }
|
|
136
|
+
let(:output) { SomeOutput.new }
|
|
137
|
+
|
|
138
|
+
it "tests something" do
|
|
139
|
+
VerifiedDouble.allow_any_instance_of(Collaborator)
|
|
140
|
+
.to receive(:some_method).with(input).and_return(output)
|
|
141
|
+
|
|
142
|
+
ObjectUnderTest.new.do_something(Collaborator.new, input)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
And the test suite does not have a contract test for the stub
|
|
148
|
+
When I run the test suite
|
|
149
|
+
Then I should be informed that the stub is unverified:
|
|
150
|
+
"""
|
|
151
|
+
The following mocks are not verified:
|
|
152
|
+
|
|
153
|
+
1. Collaborator#some_method(SomeInput)=>SomeOutput
|
|
154
|
+
"""
|
data/features/readme.md
CHANGED
|
@@ -153,12 +153,12 @@ end
|
|
|
153
153
|
Aside for instance and class doubles, VerifiedDouble also supports `any_instance` mocks:
|
|
154
154
|
|
|
155
155
|
```
|
|
156
|
-
VerifiedDouble.
|
|
157
|
-
.
|
|
158
|
-
```
|
|
156
|
+
VerifiedDouble.expect_any_instance_of(Collaborator)
|
|
157
|
+
.to receive(:some_method).with(input).and_return(output)
|
|
159
158
|
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
VerifiedDouble.allow_any_instance_of(Collaborator)
|
|
160
|
+
.to receive(:some_method).with(input).and_return(output)
|
|
161
|
+
```
|
|
162
162
|
|
|
163
163
|
## Complete documentation
|
|
164
164
|
|
|
@@ -14,6 +14,10 @@ Given /^a test that uses VerifiedDouble to stub an object:$/ do |string|
|
|
|
14
14
|
write_file 'spec/main_spec.rb', string
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
Given(/^a test that uses VerifiedDouble to stub any instance of the class:$/) do |string|
|
|
18
|
+
write_file 'spec/main_spec.rb', string
|
|
19
|
+
end
|
|
20
|
+
|
|
17
21
|
Given /^a test that uses VerifiedDouble to mock a class:$/ do |string|
|
|
18
22
|
write_file 'spec/main_spec.rb', string
|
|
19
23
|
end
|
|
@@ -34,6 +38,10 @@ Given /^the test suite does not have a contract test for the mock$/ do
|
|
|
34
38
|
# do nothing
|
|
35
39
|
end
|
|
36
40
|
|
|
41
|
+
Given /^the test suite does not have a contract test for the stub$/ do
|
|
42
|
+
# do nothing
|
|
43
|
+
end
|
|
44
|
+
|
|
37
45
|
When /^I run the test suite$/ do
|
|
38
46
|
run_simple(unescape("rspec"), false)
|
|
39
47
|
end
|
|
@@ -43,6 +51,11 @@ Then /^I should be informed that the mock is unverified:$/ do |string|
|
|
|
43
51
|
assert_success('pass')
|
|
44
52
|
end
|
|
45
53
|
|
|
54
|
+
Then /^I should be informed that the stub is unverified:$/ do |string|
|
|
55
|
+
assert_partial_output(string, all_output)
|
|
56
|
+
assert_success('pass')
|
|
57
|
+
end
|
|
58
|
+
|
|
46
59
|
Then /^I should not see any output saying the mock is unverified$/ do
|
|
47
60
|
assert_no_partial_output("The following mocks are not verified", all_output)
|
|
48
61
|
assert_success('pass')
|
|
@@ -11,14 +11,7 @@ module VerifiedDouble
|
|
|
11
11
|
|
|
12
12
|
def expect(*args)
|
|
13
13
|
if args[0].respond_to?(:can_record_interactions?)
|
|
14
|
-
|
|
15
|
-
raise "VerifiedDouble.any_instance_of doesn't support yet Rspec's " \
|
|
16
|
-
"expect/allow syntax. Please use should_receive."
|
|
17
|
-
else
|
|
18
|
-
VerifiedDouble.registry.current_double = args[0]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
VerifiedDouble.registry.current_double = args[0]
|
|
22
15
|
else
|
|
23
16
|
VerifiedDouble.registry.current_double = nil
|
|
24
17
|
end
|
|
@@ -20,14 +20,14 @@ module VerifiedDouble
|
|
|
20
20
|
elsif instance_double?
|
|
21
21
|
internal.instance_variable_get('@name').to_s
|
|
22
22
|
elsif any_instance_double?
|
|
23
|
-
internal.instance_variable_get('@
|
|
23
|
+
internal.instance_variable_get('@target').to_s
|
|
24
24
|
else
|
|
25
|
-
raise
|
|
25
|
+
raise 'Unable to handle internal #{internal.inspect}'
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def any_instance_double?
|
|
30
|
-
!! internal.instance_variable_get('@
|
|
30
|
+
!! internal.instance_variable_get('@target')
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def class_double?
|
data/lib/verified_double.rb
CHANGED
|
@@ -5,7 +5,6 @@ require 'verified_double/boolean'
|
|
|
5
5
|
require 'verified_double/can_record_interactions'
|
|
6
6
|
require 'verified_double/example_metadata'
|
|
7
7
|
require 'verified_double/is_a_class_double'
|
|
8
|
-
require 'verified_double/is_an_any_instance_double'
|
|
9
8
|
require 'verified_double/is_an_instance_double'
|
|
10
9
|
require 'verified_double/matchers'
|
|
11
10
|
require 'verified_double/method_signature'
|
|
@@ -25,10 +24,16 @@ require 'verified_double/stack_frame'
|
|
|
25
24
|
module VerifiedDouble
|
|
26
25
|
extend RSpec::Mocks::ExampleMethods
|
|
27
26
|
|
|
28
|
-
def self.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
def self.allow_any_instance_of(klass)
|
|
28
|
+
super(klass).tap do |d|
|
|
29
|
+
VerifiedDouble.registry.current_double = VerifiedDouble.record(d)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.expect_any_instance_of(klass)
|
|
34
|
+
super(klass).tap do |d|
|
|
35
|
+
VerifiedDouble.registry.current_double = VerifiedDouble.record(d)
|
|
36
|
+
end
|
|
32
37
|
end
|
|
33
38
|
|
|
34
39
|
def self.of_class(class_value, options = {})
|
|
@@ -15,15 +15,6 @@ describe VerifiedDouble::RSpecMocksSyntaxOverrides do
|
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
context "where the double arg is an RSpec::Mocks::AnyInstance::Recorder" do
|
|
19
|
-
let(:a_double) { VerifiedDouble.of_instance('Object') }
|
|
20
|
-
|
|
21
|
-
it "should tell the user to use should_receive instead" do
|
|
22
|
-
expect(lambda { expect(VerifiedDouble.any_instance_of(Object)) })
|
|
23
|
-
.to raise_error
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
18
|
context "where the double arg does not record VerifiedDouble interactions" do
|
|
28
19
|
let(:a_double) { double('Object') }
|
|
29
20
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: verified_double
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- George Mendoza
|
|
@@ -168,7 +168,6 @@ files:
|
|
|
168
168
|
- lib/verified_double/can_record_interactions.rb
|
|
169
169
|
- lib/verified_double/example_metadata.rb
|
|
170
170
|
- lib/verified_double/is_a_class_double.rb
|
|
171
|
-
- lib/verified_double/is_an_any_instance_double.rb
|
|
172
171
|
- lib/verified_double/is_an_instance_double.rb
|
|
173
172
|
- lib/verified_double/matchers.rb
|
|
174
173
|
- lib/verified_double/method_signature.rb
|