verified_double 0.7.0 → 0.8.0
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/features/CHANGELOG.markdown +5 -0
- data/features/partial_mocks.feature +60 -0
- data/features/step_definitions/verified_double_steps.rb +16 -0
- data/lib/verified_double/can_record_interactions.rb +0 -2
- data/lib/verified_double/recorded_method_signature_registry.rb +9 -1
- data/lib/verified_double/rspec_configuration.rb +1 -0
- data/lib/verified_double/rspec_mocks_syntax_overrides.rb +12 -11
- data/lib/verified_double/version.rb +1 -1
- data/spec/verified_double/can_record_interactions_spec.rb +13 -1
- data/spec/verified_double/method_signatures_report_spec.rb +14 -4
- data/spec/verified_double/rspec_mocks_syntax_overrides_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8e1baaa1b9eda731d0b34f43fccd89258e0103f
|
4
|
+
data.tar.gz: 55add943b1d237e527a18956d51f804577947bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79d26b5f3debd6e9700c4ba4ac901c905e8f444a008ac1bd552c797b8f6fbdbdea044d8a8b28dce766c6b79327eb42f1cfcab69951ebba4f7bb0e18ad7798871
|
7
|
+
data.tar.gz: 4c3a954df4a90e1e66089b0b447ef04361d305bf200632f82e7b7aa044f3549482d5c792044c81c69acf2c7c4e65e760f1e6ef99e2ff496ad92c3b9b0cf7fa98
|
data/CHANGELOG.markdown
CHANGED
data/features/CHANGELOG.markdown
CHANGED
@@ -216,3 +216,63 @@ Feature: 65. Partial mocks
|
|
216
216
|
|
217
217
|
1. ObjectUnderTest.some_method(SomeInput)=>SomeOutput
|
218
218
|
"""
|
219
|
+
|
220
|
+
And I should not be informed that the rspec mock is unverified:
|
221
|
+
"""
|
222
|
+
ObjectUnderTest#another_method(SomeInput)=>SomeOutput
|
223
|
+
"""
|
224
|
+
|
225
|
+
Scenario: Class partial mocks should not any_instance_of mocks in other tests
|
226
|
+
Given the following classes:
|
227
|
+
"""
|
228
|
+
class ObjectUnderTest
|
229
|
+
def self.do_something
|
230
|
+
some_class_method
|
231
|
+
new.some_instance_method
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.some_instance_method
|
235
|
+
SomeOutput.new
|
236
|
+
end
|
237
|
+
|
238
|
+
def self.some_class_method
|
239
|
+
SomeOutput.new
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class SomeOutput
|
244
|
+
end
|
245
|
+
"""
|
246
|
+
|
247
|
+
And a test that uses both any_instance_of and VerifiedDouble to mock a class:
|
248
|
+
"""
|
249
|
+
require 'spec_helper'
|
250
|
+
describe ObjectUnderTest do
|
251
|
+
let(:output) { SomeOutput.new }
|
252
|
+
|
253
|
+
let(:object_under_test_class) { VerifiedDouble.wrap(ObjectUnderTest) }
|
254
|
+
|
255
|
+
it "tests something with VerifiedDouble partial mock and allow_any_instance_of" do
|
256
|
+
expect(object_under_test_class)
|
257
|
+
.to receive(:some_class_method).and_return(output)
|
258
|
+
|
259
|
+
allow_any_instance_of(ObjectUnderTest)
|
260
|
+
.to receive(:some_instance_method).and_return(output)
|
261
|
+
|
262
|
+
ObjectUnderTest.do_something
|
263
|
+
end
|
264
|
+
end
|
265
|
+
"""
|
266
|
+
|
267
|
+
When I run the test suite
|
268
|
+
Then I should be informed that only the VerifiedDouble.wrap mock is unverified:
|
269
|
+
"""
|
270
|
+
The following mocks are not verified:
|
271
|
+
|
272
|
+
1. ObjectUnderTest.some_class_method()=>SomeOutput
|
273
|
+
"""
|
274
|
+
|
275
|
+
And I should not be informed that the any_instance_of mock is unverified:
|
276
|
+
"""
|
277
|
+
ObjectUnderTest.some_instance_method()=>SomeOutput
|
278
|
+
"""
|
@@ -14,6 +14,12 @@ Given /^a test that uses VerifiedDouble to mock the object under test:$/ do |str
|
|
14
14
|
write_file 'spec/main_spec.rb', string
|
15
15
|
end
|
16
16
|
|
17
|
+
Given("a test that uses both any_instance_of and VerifiedDouble to mock a " +
|
18
|
+
"class:") do |string|
|
19
|
+
|
20
|
+
write_file 'spec/main_spec.rb', string
|
21
|
+
end
|
22
|
+
|
17
23
|
Given "a test that uses both rspec-mock and VerifiedDouble to partially mock a " +
|
18
24
|
"class:" do |string|
|
19
25
|
|
@@ -77,6 +83,16 @@ Then "I should be informed that only the VerifiedDouble\.wrap mock is " +
|
|
77
83
|
assert_success('pass')
|
78
84
|
end
|
79
85
|
|
86
|
+
Then "I should not be informed that the any_instance_of mock is unverified:" do |string|
|
87
|
+
assert_no_partial_output(string, all_output)
|
88
|
+
assert_success('pass')
|
89
|
+
end
|
90
|
+
|
91
|
+
Then "I should not be informed that the rspec mock is unverified:" do |string|
|
92
|
+
assert_no_partial_output(string, all_output)
|
93
|
+
assert_success('pass')
|
94
|
+
end
|
95
|
+
|
80
96
|
Then /^I should not see any output saying the mock is unverified$/ do
|
81
97
|
assert_no_partial_output("The following mocks are not verified", all_output)
|
82
98
|
assert_success('pass')
|
@@ -8,7 +8,6 @@ module VerifiedDouble
|
|
8
8
|
def should_receive(*args)
|
9
9
|
VerifiedDouble.registry.add_method_signature(self, args[0])
|
10
10
|
super(*args).tap do |result|
|
11
|
-
VerifiedDouble.doubles_in_current_test << result
|
12
11
|
result.extend(VerifiedDouble::CanRecordInteractions)
|
13
12
|
end
|
14
13
|
end
|
@@ -16,7 +15,6 @@ module VerifiedDouble
|
|
16
15
|
def stub(*args)
|
17
16
|
VerifiedDouble.registry.add_method_signature(self, args[0])
|
18
17
|
super(*args).tap do |result|
|
19
|
-
VerifiedDouble.doubles_in_current_test << result
|
20
18
|
result.extend(VerifiedDouble::CanRecordInteractions)
|
21
19
|
end
|
22
20
|
end
|
@@ -10,5 +10,13 @@ module VerifiedDouble
|
|
10
10
|
def add_method_signature_with_current_double(method)
|
11
11
|
add_method_signature(current_double, method)
|
12
12
|
end
|
13
|
+
|
14
|
+
def update_current_double(a_double)
|
15
|
+
if VerifiedDouble.doubles_in_current_test.include?(a_double)
|
16
|
+
VerifiedDouble.registry.current_double = a_double
|
17
|
+
else
|
18
|
+
VerifiedDouble.registry.current_double = nil
|
19
|
+
end
|
20
|
+
end
|
13
21
|
end
|
14
|
-
end
|
22
|
+
end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
module VerifiedDouble
|
2
2
|
module RSpecMocksSyntaxOverrides
|
3
3
|
def allow(*args)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
VerifiedDouble.registry.update_current_double args[0]
|
5
|
+
super(*args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def allow_any_instance_of(*args)
|
9
|
+
VerifiedDouble.registry.update_current_double nil
|
9
10
|
super(*args)
|
10
11
|
end
|
11
12
|
|
12
13
|
def expect(*args)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
VerifiedDouble.registry.update_current_double args[0]
|
15
|
+
super(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def expect_any_instance_of(*args)
|
19
|
+
VerifiedDouble.registry.update_current_double nil
|
18
20
|
super(*args)
|
19
21
|
end
|
20
22
|
|
@@ -22,7 +24,6 @@ module VerifiedDouble
|
|
22
24
|
if VerifiedDouble.registry.current_double
|
23
25
|
VerifiedDouble.registry.add_method_signature_with_current_double(args[0])
|
24
26
|
super(*args).tap do |result|
|
25
|
-
VerifiedDouble.doubles_in_current_test << result
|
26
27
|
result.extend(VerifiedDouble::CanRecordInteractions)
|
27
28
|
end
|
28
29
|
else
|
@@ -14,13 +14,25 @@ describe VerifiedDouble::CanRecordInteractions do
|
|
14
14
|
expect(VerifiedDouble.registry.last.method).to eq('mocked_fake_to_s')
|
15
15
|
a_double.mocked_fake_to_s
|
16
16
|
end
|
17
|
+
|
18
|
+
it 'does not add the result to the current test doubles' do
|
19
|
+
a_double.should_receive(:mocked_fake_to_s)
|
20
|
+
expect(VerifiedDouble.doubles_in_current_test).to eq([a_double])
|
21
|
+
a_double.mocked_fake_to_s
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
describe "#stub(method)" do
|
20
26
|
it "appends a new method signature with the method to the registry", verifies_contract: 'Object#stubbed_fake_to_s()' do
|
21
|
-
|
27
|
+
a_double.stub(:stubbed_fake_to_s)
|
22
28
|
expect(VerifiedDouble.registry.last.method).to eq('stubbed_fake_to_s')
|
23
29
|
end
|
30
|
+
|
31
|
+
it 'does not add the result to the current test doubles' do
|
32
|
+
a_double.stub(:mocked_fake_to_s)
|
33
|
+
expect(VerifiedDouble.doubles_in_current_test).to eq([a_double])
|
34
|
+
a_double.mocked_fake_to_s
|
35
|
+
end
|
24
36
|
end
|
25
37
|
|
26
38
|
describe "#with(*args)" do
|
@@ -15,8 +15,13 @@ describe VerifiedDouble::MethodSignaturesReport do
|
|
15
15
|
let(:method_signature_2) {
|
16
16
|
VerifiedDouble::MethodSignature.new(class_name: 'Object', method_operator: '#', method: 'inspect') }
|
17
17
|
|
18
|
-
let(:registry)
|
19
|
-
double(:registry,
|
18
|
+
let(:registry) do
|
19
|
+
double(:registry,
|
20
|
+
'current_double' => nil,
|
21
|
+
'current_double=' => nil,
|
22
|
+
'update_current_double' => nil
|
23
|
+
)
|
24
|
+
end
|
20
25
|
|
21
26
|
let(:verified_double_module){
|
22
27
|
stub_const('VerifiedDouble', Class.new, transfer_nested_constants: true) }
|
@@ -174,8 +179,13 @@ describe VerifiedDouble::MethodSignaturesReport do
|
|
174
179
|
|
175
180
|
let(:method_signature) { VerifiedDouble::MethodSignature.new }
|
176
181
|
|
177
|
-
let(:registry)
|
178
|
-
double(:registry,
|
182
|
+
let(:registry) do
|
183
|
+
double(:registry,
|
184
|
+
'current_double' => nil,
|
185
|
+
'current_double=' => nil,
|
186
|
+
'update_current_double' => nil
|
187
|
+
)
|
188
|
+
end
|
179
189
|
|
180
190
|
it "works" do
|
181
191
|
verified_double_module.stub(:doubles_in_current_test).and_return([])
|
@@ -62,6 +62,13 @@ describe VerifiedDouble::RSpecMocksSyntaxOverrides do
|
|
62
62
|
|
63
63
|
a_double.fake_to_s
|
64
64
|
end
|
65
|
+
|
66
|
+
it 'should not add the result to the current test doubles' do
|
67
|
+
expect(a_double).to receive(some_method).and_return(some_result)
|
68
|
+
expect(VerifiedDouble.doubles_in_current_test).to eq([a_double])
|
69
|
+
|
70
|
+
a_double.fake_to_s
|
71
|
+
end
|
65
72
|
end
|
66
73
|
|
67
74
|
context "where the current double is not recording VerifiedDouble interactions" do
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Mendoza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|