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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97ca8fc74d9ad9dddff6b285850a673f46e092f1
4
- data.tar.gz: 638a65c4724ac5023ba85c717cda05c93bf9fde9
3
+ metadata.gz: e6bfd029b36750aeb01fc1a6d0176f58a7d3c623
4
+ data.tar.gz: aace4f64cbafacac1d051939faa93a6c7c1a1742
5
5
  SHA512:
6
- metadata.gz: e813041bbf2731d2b2b4f7aae3bb547c1e57cf85181da4422f563e0ad725b3b90841a9fae2d32ae1bc9597f3767077de97202b658e70880596d315c0af5d51db
7
- data.tar.gz: 3180a6b9822c22912b9117cc993be47ebbfe8770c5bef2e3304a706005f141741b731396598e74528a3f03a4da0243a97d9a593c76a192fcacd35607f462b6bb
6
+ metadata.gz: 90eda38fbddf5d17f03df6f06bbc23e099598564e9329fb6e891d9dfb3516de474352e46f5e4840cf3252ca03082554e6324c38556ad272fb464d745a95315b4
7
+ data.tar.gz: 9fbae516d65fbafc7f748479c147eb8fb35f62f1a0d450940f397142d007038fc6fc000a6e920c22e70b344a87c99144eea4a4913c56b00d84e219877de992fc
@@ -1,3 +1,8 @@
1
+ 0.6.0 - 2013-12-28
2
+ ------------------
3
+
4
+ * Implement partial mocks.
5
+
1
6
  0.5.3 - 2013-12-26
2
7
  ------------------
3
8
 
data/Guardfile CHANGED
@@ -1,6 +1,6 @@
1
1
  guard :rspec do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
5
5
  end
6
6
 
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 `any_instance` mocks:
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)
@@ -1,3 +1,8 @@
1
+ 0.6.0 - 2013-12-28
2
+ ------------------
3
+
4
+ * Implement partial mocks.
5
+
1
6
  0.5.3 - 2013-12-26
2
7
  ------------------
3
8
 
@@ -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
+ """
@@ -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 `any_instance` mocks:
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
@@ -37,7 +37,9 @@ module VerifiedDouble
37
37
  end
38
38
 
39
39
  def self.of_class(class_value, options = {})
40
- options[:transfer_nested_constants] = true if options[:transfer_nested_constants].nil?
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
@@ -22,7 +22,7 @@ module VerifiedDouble
22
22
  elsif any_instance_double?
23
23
  internal.instance_variable_get('@target').to_s
24
24
  else
25
- raise 'Unable to handle internal #{internal.inspect}'
25
+ internal.class.name
26
26
  end
27
27
  end
28
28
 
@@ -1,3 +1,3 @@
1
1
  module VerifiedDouble
2
- VERSION = "0.5.3"
2
+ VERSION = "0.6"
3
3
  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.5.3
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-26 00:00:00.000000000 Z
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