verified_double 0.6.1 → 0.7.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 +7 -0
- data/features/CHANGELOG.markdown +7 -0
- data/features/partial_mocks.feature +56 -0
- data/features/step_definitions/verified_double_steps.rb +18 -1
- data/lib/verified_double.rb +5 -0
- data/lib/verified_double/can_record_interactions.rb +8 -6
- data/lib/verified_double/rspec_configuration.rb +5 -1
- data/lib/verified_double/rspec_mocks_syntax_overrides.rb +6 -3
- data/lib/verified_double/version.rb +1 -1
- data/spec/verified_double/can_record_interactions_spec.rb +3 -2
- data/spec/verified_double/method_signatures_report_spec.rb +4 -1
- 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: 3b7ae16d1fbe0432c903b73550c4da1c0abad46f
|
4
|
+
data.tar.gz: 95596257e58d1597f9ad4294fab12552d12b07f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7a957cdba5ce4f2339f3c56e15320625d5b4a1610ffbfba4a3377378013130d978067c11887c0c8c99ad8fbbfef9c9780f315e9a0930fb0fbdc2769bb5eb84b
|
7
|
+
data.tar.gz: 401ff433e309a8691d8fc8ec1382807d8bbebd1a286460ed79667066952500a8ee345d9a711908cb9bc7094c249aea1d2897971a0e08861ccbbf39d291421882
|
data/CHANGELOG.markdown
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
0.7.0 - 2014-01-22
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Fix: `VerifiedDouble.wrap(klass)` doesn't get cleared after the test where it
|
5
|
+
is called. As a result, expectations of `klass` in other tests gets recorded by
|
6
|
+
VerifiedDouble.
|
7
|
+
|
1
8
|
0.6.1 - 2013-12-30
|
2
9
|
------------------
|
3
10
|
|
data/features/CHANGELOG.markdown
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
0.7.0 - 2014-01-22
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Fix: `VerifiedDouble.wrap(klass)` doesn't get cleared after the test where it
|
5
|
+
is called. As a result, expectations of `klass` in other tests gets recorded by
|
6
|
+
VerifiedDouble.
|
7
|
+
|
1
8
|
0.6.1 - 2013-12-30
|
2
9
|
------------------
|
3
10
|
|
@@ -160,3 +160,59 @@ Feature: 65. Partial mocks
|
|
160
160
|
|
161
161
|
1. ObjectUnderTest.some_method(SomeInput)=>SomeOutput
|
162
162
|
"""
|
163
|
+
|
164
|
+
Scenario: Class partial mocks should not affect the class in other tests
|
165
|
+
Given the following classes:
|
166
|
+
"""
|
167
|
+
class ObjectUnderTest
|
168
|
+
def self.do_something(input)
|
169
|
+
some_method(input)
|
170
|
+
another_method(input)
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.another_method(input)
|
174
|
+
SomeOutput.new
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.some_method(input)
|
178
|
+
SomeOutput.new
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class SomeInput
|
183
|
+
end
|
184
|
+
|
185
|
+
class SomeOutput
|
186
|
+
end
|
187
|
+
"""
|
188
|
+
|
189
|
+
And a test that uses both rspec-mock and VerifiedDouble to partially mock a class:
|
190
|
+
"""
|
191
|
+
require 'spec_helper'
|
192
|
+
describe ObjectUnderTest do
|
193
|
+
let(:input) { SomeInput.new }
|
194
|
+
let(:output) { SomeOutput.new }
|
195
|
+
|
196
|
+
it "tests something with VerifiedDouble partial mock" do
|
197
|
+
expect(VerifiedDouble.wrap(ObjectUnderTest))
|
198
|
+
.to receive(:some_method).with(input).and_return(output)
|
199
|
+
|
200
|
+
ObjectUnderTest.do_something(input)
|
201
|
+
end
|
202
|
+
|
203
|
+
it "tests something with rspec-mock" do
|
204
|
+
expect(ObjectUnderTest)
|
205
|
+
.to receive(:another_method).with(input).and_return(output)
|
206
|
+
|
207
|
+
ObjectUnderTest.do_something(input)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
"""
|
211
|
+
|
212
|
+
When I run the test suite
|
213
|
+
Then I should be informed that only the VerifiedDouble.wrap mock is unverified:
|
214
|
+
"""
|
215
|
+
The following mocks are not verified:
|
216
|
+
|
217
|
+
1. ObjectUnderTest.some_method(SomeInput)=>SomeOutput
|
218
|
+
"""
|
@@ -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 rspec-mock and VerifiedDouble to partially 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 VerifiedDouble to stub an object:$/ do |string|
|
18
24
|
write_file 'spec/main_spec.rb', string
|
19
25
|
end
|
@@ -34,7 +40,11 @@ Given /^the test suite has a contract test for the stub:$/ do |string|
|
|
34
40
|
write_file 'spec/contract_test_for_main_spec.rb', string
|
35
41
|
end
|
36
42
|
|
37
|
-
Given
|
43
|
+
Given /^the test suite has another test mocking the class with rspec\-mock:$/ do |string|
|
44
|
+
write_file 'spec/another_spec.rb', string
|
45
|
+
end
|
46
|
+
|
47
|
+
Given /^the test suite is configured to use VerifiedDouble:$/ do |string|
|
38
48
|
write_file 'spec/spec_helper.rb', string
|
39
49
|
end
|
40
50
|
|
@@ -60,6 +70,13 @@ Then /^I should be informed that the stub is unverified:$/ do |string|
|
|
60
70
|
assert_success('pass')
|
61
71
|
end
|
62
72
|
|
73
|
+
Then "I should be informed that only the VerifiedDouble\.wrap mock is " +
|
74
|
+
"unverified:" do |string|
|
75
|
+
|
76
|
+
assert_partial_output(string, all_output)
|
77
|
+
assert_success('pass')
|
78
|
+
end
|
79
|
+
|
63
80
|
Then /^I should not see any output saying the mock is unverified$/ do
|
64
81
|
assert_no_partial_output("The following mocks are not verified", all_output)
|
65
82
|
assert_success('pass')
|
data/lib/verified_double.rb
CHANGED
@@ -30,6 +30,10 @@ module VerifiedDouble
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
def self.doubles_in_current_test
|
34
|
+
@doubles_in_current_test ||= []
|
35
|
+
end
|
36
|
+
|
33
37
|
def self.expect_any_instance_of(klass)
|
34
38
|
super(klass).tap do |d|
|
35
39
|
VerifiedDouble.registry.current_double = VerifiedDouble.record(d)
|
@@ -62,6 +66,7 @@ module VerifiedDouble
|
|
62
66
|
end
|
63
67
|
|
64
68
|
def self.record(a_double)
|
69
|
+
VerifiedDouble.doubles_in_current_test << a_double
|
65
70
|
a_double.extend(VerifiedDouble::CanRecordInteractions)
|
66
71
|
a_double
|
67
72
|
end
|
@@ -5,18 +5,20 @@ module VerifiedDouble
|
|
5
5
|
super(*return_values)
|
6
6
|
end
|
7
7
|
|
8
|
-
def can_record_interactions?
|
9
|
-
true
|
10
|
-
end
|
11
|
-
|
12
8
|
def should_receive(*args)
|
13
9
|
VerifiedDouble.registry.add_method_signature(self, args[0])
|
14
|
-
super(*args).tap
|
10
|
+
super(*args).tap do |result|
|
11
|
+
VerifiedDouble.doubles_in_current_test << result
|
12
|
+
result.extend(VerifiedDouble::CanRecordInteractions)
|
13
|
+
end
|
15
14
|
end
|
16
15
|
|
17
16
|
def stub(*args)
|
18
17
|
VerifiedDouble.registry.add_method_signature(self, args[0])
|
19
|
-
super(*args).tap
|
18
|
+
super(*args).tap do |result|
|
19
|
+
VerifiedDouble.doubles_in_current_test << result
|
20
|
+
result.extend(VerifiedDouble::CanRecordInteractions)
|
21
|
+
end
|
20
22
|
end
|
21
23
|
|
22
24
|
def with(*args)
|
@@ -4,7 +4,11 @@ RSpec.configure do |config|
|
|
4
4
|
config.before do
|
5
5
|
self.extend VerifiedDouble::RSpecMocksSyntaxOverrides
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
|
+
config.after do
|
9
|
+
VerifiedDouble.doubles_in_current_test.clear
|
10
|
+
end
|
11
|
+
|
8
12
|
config.after :suite do
|
9
13
|
VerifiedDouble.report_unverified_signatures(self)
|
10
14
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module VerifiedDouble
|
2
2
|
module RSpecMocksSyntaxOverrides
|
3
3
|
def allow(*args)
|
4
|
-
if args[0]
|
4
|
+
if VerifiedDouble.doubles_in_current_test.include?(args[0])
|
5
5
|
VerifiedDouble.registry.current_double = args[0]
|
6
6
|
else
|
7
7
|
VerifiedDouble.registry.current_double = nil
|
@@ -10,7 +10,7 @@ module VerifiedDouble
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def expect(*args)
|
13
|
-
if args[0]
|
13
|
+
if VerifiedDouble.doubles_in_current_test.include?(args[0])
|
14
14
|
VerifiedDouble.registry.current_double = args[0]
|
15
15
|
else
|
16
16
|
VerifiedDouble.registry.current_double = nil
|
@@ -21,7 +21,10 @@ module VerifiedDouble
|
|
21
21
|
def receive(*args)
|
22
22
|
if VerifiedDouble.registry.current_double
|
23
23
|
VerifiedDouble.registry.add_method_signature_with_current_double(args[0])
|
24
|
-
super(*args).tap
|
24
|
+
super(*args).tap do |result|
|
25
|
+
VerifiedDouble.doubles_in_current_test << result
|
26
|
+
result.extend(VerifiedDouble::CanRecordInteractions)
|
27
|
+
end
|
25
28
|
else
|
26
29
|
super(*args)
|
27
30
|
end
|
@@ -4,6 +4,7 @@ describe VerifiedDouble::CanRecordInteractions do
|
|
4
4
|
let(:a_double){ double('Object') }
|
5
5
|
|
6
6
|
before do
|
7
|
+
VerifiedDouble.doubles_in_current_test << a_double
|
7
8
|
a_double.extend(VerifiedDouble::CanRecordInteractions)
|
8
9
|
end
|
9
10
|
|
@@ -13,7 +14,7 @@ describe VerifiedDouble::CanRecordInteractions do
|
|
13
14
|
expect(VerifiedDouble.registry.last.method).to eq('mocked_fake_to_s')
|
14
15
|
a_double.mocked_fake_to_s
|
15
16
|
end
|
16
|
-
end
|
17
|
+
end
|
17
18
|
|
18
19
|
describe "#stub(method)" do
|
19
20
|
it "appends a new method signature with the method to the registry", verifies_contract: 'Object#stubbed_fake_to_s()' do
|
@@ -44,4 +45,4 @@ describe VerifiedDouble::CanRecordInteractions do
|
|
44
45
|
a_double.fake_to_s(:arg_1, :arg_2)
|
45
46
|
end
|
46
47
|
end
|
47
|
-
end
|
48
|
+
end
|
@@ -22,6 +22,7 @@ describe VerifiedDouble::MethodSignaturesReport do
|
|
22
22
|
stub_const('VerifiedDouble', Class.new, transfer_nested_constants: true) }
|
23
23
|
|
24
24
|
it "sets distinct signatures from the registry" do
|
25
|
+
verified_double_module.stub(:doubles_in_current_test).and_return([])
|
25
26
|
verified_double_module
|
26
27
|
.should_receive(:registry)
|
27
28
|
.at_least(:once)
|
@@ -177,11 +178,13 @@ describe VerifiedDouble::MethodSignaturesReport do
|
|
177
178
|
double(:registry, 'current_double' => nil, 'current_double=' => nil) }
|
178
179
|
|
179
180
|
it "works" do
|
181
|
+
verified_double_module.stub(:doubles_in_current_test).and_return([])
|
182
|
+
|
180
183
|
verified_double_module
|
181
184
|
.should_receive(:registry)
|
182
185
|
.at_least(:once)
|
183
186
|
.and_return(registry)
|
184
|
-
|
187
|
+
|
185
188
|
expect(verified_double_module)
|
186
189
|
.to receive(:verified_signatures_from_matchers)
|
187
190
|
.and_return([method_signature])
|
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.7.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:
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|