verified_double 0.3.0 → 0.4.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.
@@ -1,4 +1,21 @@
1
+ 0.4.0 - 2013-07-28
2
+ ------------------
3
+
4
+ [#7] Pass: I should be able to use the RSpec's new expect syntax with
5
+ VerifiedDouble.
6
+
7
+ [#7] Require verified_double/rspec_configuration in order to integrate
8
+ verified_double with rspec.
9
+
10
+ [#18] Fix Scenario: stubbed doubles using hash syntax are no longer being
11
+ recorded after 0.3.0.
12
+
13
+ [#19] Ensure: if `VerifiedDouble.of_instance(class_name, method_stubs={})` is
14
+ used a argument or return value value of an expectation, then it should
15
+ not interfere with the method signature recording of the expectation.
16
+
1
17
  0.3.0 - 2013-07-19
18
+ ------------------
2
19
 
3
20
  * [#17] Major refactor: extend RSpec doubles with VerifiedDouble recording
4
21
  functionality. No more need for RecordingDouble.
data/README.md CHANGED
@@ -7,7 +7,7 @@ VerifiedDouble is a gem for verifying rspec mocks. The gem works similar to [rsp
7
7
  For example, let's say I mocked the created_at method of a model like this:
8
8
 
9
9
  item = VerifiedDouble.of_instance(Item)
10
- item.should_receive(:created_at).and_return(Time.now)
10
+ expect(item).to receive(:created_at).and_return(Time.now)
11
11
 
12
12
  When running the tests, the gem looks for a "contract test" tagged with the method's signature. This test should ensure that calling #created_at on Item will return a Time object.
13
13
 
@@ -19,13 +19,26 @@ If this test does not exist, the gem will complain that the mock is not verified
19
19
 
20
20
  I got the idea from http://www.infoq.com/presentations/integration-tests-scam, an old (2009) talk that still has some fresh insights on dealing with API changes in your mocked tests.
21
21
 
22
+ Usage
23
+ -----
24
+
25
+ Require `verified_double/rspec_configuration` in your spec_helper.rb to integrate VerifiedDouble with rspec. If you want verified_double to be run only as needed, create a separate verified_spec_helper.rb:
26
+
27
+ # spec/verified_spec_helper.rb
28
+ require 'spec_helper'
29
+ require 'verified_double/rspec_configuration'
30
+
31
+ And require it when running rspec:
32
+
33
+ rspec -r ./spec/verified_spec_helper.rb
34
+
22
35
  You can learn more about using the gem at https://www.relishapp.com/gsmendoza/verified-double.
23
36
 
24
37
  Actively tested against
25
38
  -----------------------
26
39
 
27
40
  * Ruby 1.9.3
28
- * RSpec 2.13
41
+ * RSpec 2.14
29
42
 
30
43
 
31
44
  Alternatives
@@ -36,13 +49,11 @@ Alternatives
36
49
  Caveats
37
50
  -------
38
51
 
39
- VerifiedDouble is still in its infancy, but I hope it's usable for the most common cases.
40
-
41
- * If you check the RelishApp doc, the gem only supports a subset of rspec-mock's API. Please post an issue at http://github.com/gsmendoza/verified_double if you need support for any particular rspec-mock API.
52
+ * With 0.3.0, doubles created with VerifiedDouble.of_instance() and VerifiedDouble.of_class() are now VerifiedDouble-extended RSpec doubles. As a result, they should function like regular RSpec doubles. However, VerifiedDouble still doesn't have support for [RSpec mock argument matchers](https://github.com/rspec/rspec-mocks#argument-matchers). Please post an issue at http://github.com/gsmendoza/verified_double if you need support for any particular rspec-mock API.
42
53
 
43
54
  * The [method documentation](http://rubydoc.info/gems/verified_double) is pretty empty at this point :p I'm planning to use yard-spec to document the methods but that gem doesn't support rspec context blocks. I'll try to work on that soon.
44
55
 
45
56
  Special thanks
46
57
  --------------
47
58
 
48
- To [Thomas Sinclair](https://twitter.com/anathematic) and [Inner Core Designs](http://icdesign.com.au) for sponsoring this gem :)
59
+ To [Thomas Sinclair](https://twitter.com/anathematic) of [Inner Core Designs](http://icdesign.com.au) for sponsoring this gem :)
@@ -1,4 +1,21 @@
1
+ 0.4.0 - 2013-07-28
2
+ ------------------
3
+
4
+ [#7] Pass: I should be able to use the RSpec's new expect syntax with
5
+ VerifiedDouble.
6
+
7
+ [#7] Require verified_double/rspec_configuration in order to integrate
8
+ verified_double with rspec.
9
+
10
+ [#18] Fix Scenario: stubbed doubles using hash syntax are no longer being
11
+ recorded after 0.3.0.
12
+
13
+ [#19] Ensure: if `VerifiedDouble.of_instance(class_name, method_stubs={})` is
14
+ used a argument or return value value of an expectation, then it should
15
+ not interfere with the method signature recording of the expectation.
16
+
1
17
  0.3.0 - 2013-07-19
18
+ ------------------
2
19
 
3
20
  * [#17] Major refactor: extend RSpec doubles with VerifiedDouble recording
4
21
  functionality. No more need for RecordingDouble.
@@ -19,18 +19,11 @@ Feature: 05. Accessor method contracts
19
19
  end
20
20
  """
21
21
 
22
- And the test suite includes VerifiedDouble to verify doubles with accessor methods:
22
+ And the test suite is configured to use VerifiedDouble:
23
23
  """
24
24
  require 'verified_double'
25
+ require 'verified_double/rspec_configuration'
25
26
  require 'main'
26
-
27
- RSpec.configure do |config|
28
- config.include VerifiedDouble::Matchers
29
-
30
- config.after :suite do
31
- VerifiedDouble.report_unverified_signatures(self)
32
- end
33
- end
34
27
  """
35
28
 
36
29
  Scenario: Verifying mocks for accessors
@@ -17,16 +17,11 @@ Feature: 04. Customizing arguments and return values
17
17
  end
18
18
  """
19
19
 
20
- And the test suite has an after(:suite) callback asking VerifiedDouble to report unverified doubles:
20
+ And the test suite is configured to use VerifiedDouble:
21
21
  """
22
22
  require 'verified_double'
23
+ require 'verified_double/rspec_configuration'
23
24
  require 'main'
24
-
25
- RSpec.configure do |config|
26
- config.after :suite do
27
- VerifiedDouble.report_unverified_signatures(self)
28
- end
29
- end
30
25
  """
31
26
 
32
27
  And a test that uses VerifiedDouble to mock an object:
@@ -38,7 +33,7 @@ Feature: 04. Customizing arguments and return values
38
33
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
39
34
 
40
35
  it "tests something" do
41
- instance_double.should_receive(:some_method).with(input).and_return(output)
36
+ expect(instance_double).to receive(:some_method).with(input).and_return(output)
42
37
  ObjectUnderTest.new.do_something(instance_double, input)
43
38
  end
44
39
  end
@@ -7,7 +7,7 @@ VerifiedDouble is a gem for verifying rspec mocks. The gem works similar to [rsp
7
7
  For example, let's say I mocked the created_at method of a model like this:
8
8
 
9
9
  item = VerifiedDouble.of_instance(Item)
10
- item.should_receive(:created_at).and_return(Time.now)
10
+ expect(item).to receive(:created_at).and_return(Time.now)
11
11
 
12
12
  When running the tests, the gem looks for a "contract test" tagged with the method's signature. This test should ensure that calling #created_at on Item will return a Time object.
13
13
 
@@ -19,13 +19,26 @@ If this test does not exist, the gem will complain that the mock is not verified
19
19
 
20
20
  I got the idea from http://www.infoq.com/presentations/integration-tests-scam, an old (2009) talk that still has some fresh insights on dealing with API changes in your mocked tests.
21
21
 
22
+ Usage
23
+ -----
24
+
25
+ Require `verified_double/rspec_configuration` in your spec_helper.rb to integrate VerifiedDouble with rspec. If you want verified_double to be run only as needed, create a separate verified_spec_helper.rb:
26
+
27
+ # spec/verified_spec_helper.rb
28
+ require 'spec_helper'
29
+ require 'verified_double/rspec_configuration'
30
+
31
+ And require it when running rspec:
32
+
33
+ rspec -r ./spec/verified_spec_helper.rb
34
+
22
35
  You can learn more about using the gem at https://www.relishapp.com/gsmendoza/verified-double.
23
36
 
24
37
  Actively tested against
25
38
  -----------------------
26
39
 
27
40
  * Ruby 1.9.3
28
- * RSpec 2.13
41
+ * RSpec 2.14
29
42
 
30
43
 
31
44
  Alternatives
@@ -36,13 +49,11 @@ Alternatives
36
49
  Caveats
37
50
  -------
38
51
 
39
- VerifiedDouble is still in its infancy, but I hope it's usable for the most common cases.
40
-
41
- * If you check the RelishApp doc, the gem only supports a subset of rspec-mock's API. Please post an issue at http://github.com/gsmendoza/verified_double if you need support for any particular rspec-mock API.
52
+ * With 0.3.0, doubles created with VerifiedDouble.of_instance() and VerifiedDouble.of_class() are now VerifiedDouble-extended RSpec doubles. As a result, they should function like regular RSpec doubles. However, VerifiedDouble still doesn't have support for [RSpec mock argument matchers](https://github.com/rspec/rspec-mocks#argument-matchers). Please post an issue at http://github.com/gsmendoza/verified_double if you need support for any particular rspec-mock API.
42
53
 
43
54
  * The [method documentation](http://rubydoc.info/gems/verified_double) is pretty empty at this point :p I'm planning to use yard-spec to document the methods but that gem doesn't support rspec context blocks. I'll try to work on that soon.
44
55
 
45
56
  Special thanks
46
57
  --------------
47
58
 
48
- To [Thomas Sinclair](https://twitter.com/anathematic) and [Inner Core Designs](http://icdesign.com.au) for sponsoring this gem :)
59
+ To [Thomas Sinclair](https://twitter.com/anathematic) of [Inner Core Designs](http://icdesign.com.au) for sponsoring this gem :)
@@ -31,27 +31,11 @@ Feature: 03. Rspec Mock compatibility
31
31
  end
32
32
  """
33
33
 
34
- And the test suite has a contract test for the mock:
35
- """
36
- require 'spec_helper'
37
-
38
- describe 'Collaborator' do
39
- it "tests something", verifies_contract: 'Collaborator#some_method(SomeInput)=>SomeOutput' do
40
- # do nothing
41
- end
42
- end
43
- """
44
-
45
- And the test suite has an after(:suite) callback asking VerifiedDouble to report unverified doubles:
34
+ And the test suite is configured to use VerifiedDouble:
46
35
  """
47
36
  require 'verified_double'
37
+ require 'verified_double/rspec_configuration'
48
38
  require 'main'
49
-
50
- RSpec.configure do |config|
51
- config.after :suite do
52
- VerifiedDouble.report_unverified_signatures(self)
53
- end
54
- end
55
39
  """
56
40
 
57
41
  Scenario: once
@@ -64,14 +48,20 @@ Feature: 03. Rspec Mock compatibility
64
48
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
65
49
 
66
50
  it "tests something" do
67
- instance_double.should_receive(:some_method).with(input).once.and_return(output)
51
+ expect(instance_double).to receive(:some_method).with(input).once.and_return(output)
68
52
  ObjectUnderTest.new.do_something(instance_double, input)
69
53
  end
70
54
  end
71
55
  """
72
56
 
73
57
  When I run the test suite
74
- Then I should not see any output saying the stub is unverified
58
+
59
+ Then I should be informed that the mock is unverified:
60
+ """
61
+ The following mocks are not verified:
62
+
63
+ 1. Collaborator#some_method(SomeInput)=>SomeOutput
64
+ """
75
65
 
76
66
  Scenario: twice
77
67
  Given a test that uses VerifiedDouble to mock an object:
@@ -83,14 +73,20 @@ Feature: 03. Rspec Mock compatibility
83
73
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
84
74
 
85
75
  it "tests something" do
86
- instance_double.should_receive(:some_method).with(input).twice.and_return(output)
76
+ expect(instance_double).to receive(:some_method).with(input).twice.and_return(output)
87
77
  ObjectUnderTest.new.do_something_twice(instance_double, input)
88
78
  end
89
79
  end
90
80
  """
91
81
 
92
82
  When I run the test suite
93
- Then I should not see any output saying the stub is unverified
83
+
84
+ Then I should be informed that the mock is unverified:
85
+ """
86
+ The following mocks are not verified:
87
+
88
+ 1. Collaborator#some_method(SomeInput)=>SomeOutput
89
+ """
94
90
 
95
91
  Scenario: exactly
96
92
  Given a test that uses VerifiedDouble to mock an object:
@@ -102,14 +98,19 @@ Feature: 03. Rspec Mock compatibility
102
98
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
103
99
 
104
100
  it "tests something" do
105
- instance_double.should_receive(:some_method).with(input).exactly(1).and_return(output)
101
+ expect(instance_double).to receive(:some_method).with(input).exactly(1).and_return(output)
106
102
  ObjectUnderTest.new.do_something(instance_double, input)
107
103
  end
108
104
  end
109
105
  """
110
106
 
111
107
  When I run the test suite
112
- Then I should not see any output saying the stub is unverified
108
+ Then I should be informed that the mock is unverified:
109
+ """
110
+ The following mocks are not verified:
111
+
112
+ 1. Collaborator#some_method(SomeInput)=>SomeOutput
113
+ """
113
114
 
114
115
  Scenario: at_least
115
116
  Given a test that uses VerifiedDouble to mock an object:
@@ -121,14 +122,19 @@ Feature: 03. Rspec Mock compatibility
121
122
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
122
123
 
123
124
  it "tests something" do
124
- instance_double.should_receive(:some_method).with(input).at_least(:once).and_return(output)
125
+ expect(instance_double).to receive(:some_method).with(input).at_least(:once).and_return(output)
125
126
  ObjectUnderTest.new.do_something(instance_double, input)
126
127
  end
127
128
  end
128
129
  """
129
130
 
130
131
  When I run the test suite
131
- Then I should not see any output saying the stub is unverified
132
+ Then I should be informed that the mock is unverified:
133
+ """
134
+ The following mocks are not verified:
135
+
136
+ 1. Collaborator#some_method(SomeInput)=>SomeOutput
137
+ """
132
138
 
133
139
  Scenario: at_most
134
140
  Given a test that uses VerifiedDouble to mock an object:
@@ -140,34 +146,20 @@ Feature: 03. Rspec Mock compatibility
140
146
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
141
147
 
142
148
  it "tests something" do
143
- instance_double.should_receive(:some_method).with(input).at_most(:once).and_return(output)
149
+ expect(instance_double).to receive(:some_method).with(input).at_most(:once).and_return(output)
144
150
  ObjectUnderTest.new.do_something(instance_double, input)
145
151
  end
146
152
  end
147
153
  """
148
154
 
149
155
  When I run the test suite
150
- Then I should not see any output saying the stub is unverified
151
-
152
- Scenario: any_number_of_times
153
- Given a test that uses VerifiedDouble to mock an object:
156
+ Then I should be informed that the mock is unverified:
154
157
  """
155
- require 'spec_helper'
156
- describe ObjectUnderTest do
157
- let(:input) { SomeInput.new }
158
- let(:output) { SomeOutput.new }
159
- let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
158
+ The following mocks are not verified:
160
159
 
161
- it "tests something" do
162
- instance_double.should_receive(:some_method).with(input).any_number_of_times.and_return(output)
163
- ObjectUnderTest.new.do_something(instance_double, input)
164
- end
165
- end
160
+ 1. Collaborator#some_method(SomeInput)=>SomeOutput
166
161
  """
167
162
 
168
- When I run the test suite
169
- Then I should not see any output saying the stub is unverified
170
-
171
163
  Scenario: and_raise
172
164
  Given a test that uses VerifiedDouble to mock an object:
173
165
  """
@@ -179,25 +171,20 @@ Feature: 03. Rspec Mock compatibility
179
171
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
180
172
 
181
173
  it "tests something" do
182
- instance_double.should_receive(:some_method).with(input).and_raise(error)
174
+ expect(instance_double).to receive(:some_method).with(input).and_raise(error)
183
175
  expect { ObjectUnderTest.new.do_something(instance_double, input) }.to raise_error(error)
184
176
  end
185
177
  end
186
178
  """
187
179
 
188
- And the test suite has a contract test for the mock:
180
+ When I run the test suite
181
+ Then I should be informed that the mock is unverified:
189
182
  """
190
- require 'spec_helper'
183
+ The following mocks are not verified:
191
184
 
192
- describe 'Collaborator' do
193
- it "tests something", verifies_contract: 'Collaborator#some_method(SomeInput)' do
194
- # do nothing
195
- end
196
- end
185
+ 1. Collaborator#some_method(SomeInput)
197
186
  """
198
187
 
199
- When I run the test suite
200
- Then I should not see any output saying the stub is unverified
201
188
  Scenario: and_throw
202
189
  Given a test that uses VerifiedDouble to mock an object:
203
190
  """
@@ -209,22 +196,16 @@ Feature: 03. Rspec Mock compatibility
209
196
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
210
197
 
211
198
  it "tests something" do
212
- instance_double.should_receive(:some_method).with(input).and_throw(error_symbol)
199
+ expect(instance_double).to receive(:some_method).with(input).and_throw(error_symbol)
213
200
  expect { ObjectUnderTest.new.do_something(instance_double, input) }.to throw_symbol(error_symbol)
214
201
  end
215
202
  end
216
203
  """
217
204
 
218
- And the test suite has a contract test for the mock:
205
+ When I run the test suite
206
+ Then I should be informed that the mock is unverified:
219
207
  """
220
- require 'spec_helper'
208
+ The following mocks are not verified:
221
209
 
222
- describe 'Collaborator' do
223
- it "tests something", verifies_contract: 'Collaborator#some_method(SomeInput)' do
224
- # do nothing
225
- end
226
- end
210
+ 1. Collaborator#some_method(SomeInput)
227
211
  """
228
-
229
- When I run the test suite
230
- Then I should not see any output saying the stub is unverified
@@ -2,14 +2,6 @@ Given /^the following classes:$/ do |string|
2
2
  write_file 'lib/main.rb', string
3
3
  end
4
4
 
5
- Given /^the test suite includes VerifiedDouble to verify doubles with accessor methods:$/ do |string|
6
- write_file 'spec/spec_helper.rb', string
7
- end
8
-
9
- Given /^the test suite has an after\(:suite\) callback asking VerifiedDouble to report unverified doubles:$/ do |string|
10
- write_file 'spec/spec_helper.rb', string
11
- end
12
-
13
5
  Given /^a test that uses VerifiedDouble to mock an object:$/ do |string|
14
6
  write_file 'spec/main_spec.rb', string
15
7
  end
@@ -30,6 +22,10 @@ Given /^the test suite has a contract test for the stub:$/ do |string|
30
22
  write_file 'spec/contract_test_for_main_spec.rb', string
31
23
  end
32
24
 
25
+ Given(/^the test suite is configured to use VerifiedDouble:$/) do |string|
26
+ write_file 'spec/spec_helper.rb', string
27
+ end
28
+
33
29
  Given /^the test suite does not have a contract test for the mock$/ do
34
30
  # do nothing
35
31
  end
@@ -30,16 +30,11 @@ Feature: 01. Verified mocks
30
30
  end
31
31
  """
32
32
 
33
- And the test suite has an after(:suite) callback asking VerifiedDouble to report unverified doubles:
33
+ And the test suite is configured to use VerifiedDouble:
34
34
  """
35
35
  require 'verified_double'
36
+ require 'verified_double/rspec_configuration'
36
37
  require 'main'
37
-
38
- RSpec.configure do |config|
39
- config.after :suite do
40
- VerifiedDouble.report_unverified_signatures(self)
41
- end
42
- end
43
38
  """
44
39
 
45
40
  Scenario: Verified instance doubles
@@ -52,7 +47,7 @@ Feature: 01. Verified mocks
52
47
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
53
48
 
54
49
  it "tests something" do
55
- instance_double.should_receive(:some_method).with(input).and_return(output)
50
+ expect(instance_double).to receive(:some_method).with(input).and_return(output)
56
51
  ObjectUnderTest.new.do_something(instance_double, input)
57
52
  end
58
53
  end
@@ -82,7 +77,7 @@ Feature: 01. Verified mocks
82
77
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
83
78
 
84
79
  it "tests something" do
85
- instance_double.should_receive(:some_method).with(input).and_return(output)
80
+ expect(instance_double).to receive(:some_method).with(input).and_return(output)
86
81
  ObjectUnderTest.new.do_something(instance_double, input)
87
82
  end
88
83
  end
@@ -107,7 +102,7 @@ Feature: 01. Verified mocks
107
102
  let(:class_double) { VerifiedDouble.of_class('Collaborator') }
108
103
 
109
104
  it "tests something" do
110
- class_double.should_receive(:some_method).with(input).and_return(output)
105
+ expect(class_double).to receive(:some_method).with(input).and_return(output)
111
106
  ObjectUnderTest.do_something(input)
112
107
  end
113
108
  end
@@ -137,7 +132,7 @@ Feature: 01. Verified mocks
137
132
  let(:class_double) { VerifiedDouble.of_class('Collaborator') }
138
133
 
139
134
  it "tests something" do
140
- class_double.should_receive(:some_method).with(input).and_return(output)
135
+ expect(class_double).to receive(:some_method).with(input).and_return(output)
141
136
  ObjectUnderTest.new.do_something(class_double, input)
142
137
  end
143
138
  end
@@ -23,17 +23,13 @@ Feature: 02. Verified stubs
23
23
  end
24
24
  """
25
25
 
26
- And the test suite has an after(:suite) callback asking VerifiedDouble to report unverified doubles:
26
+ And the test suite is configured to use VerifiedDouble:
27
27
  """
28
28
  require 'verified_double'
29
+ require 'verified_double/rspec_configuration'
29
30
  require 'main'
30
-
31
- RSpec.configure do |config|
32
- config.after :suite do
33
- VerifiedDouble.report_unverified_signatures(self)
34
- end
35
- end
36
31
  """
32
+
37
33
  Scenario: Stubbed doubles
38
34
  Given a test that uses VerifiedDouble to stub an object:
39
35
  """
@@ -44,26 +40,20 @@ Feature: 02. Verified stubs
44
40
  let(:instance_double) { VerifiedDouble.of_instance('Collaborator') }
45
41
 
46
42
  it "tests something" do
47
- instance_double.stub(:some_method).with(input).and_return(output)
43
+ allow(instance_double).to receive(:some_method).with(input).and_return(output)
48
44
  ObjectUnderTest.new.do_something(instance_double, input)
49
45
  end
50
46
  end
51
47
  """
52
48
 
53
- And the test suite has a contract test for the stub:
49
+ When I run the test suite
50
+ Then I should be informed that the mock is unverified:
54
51
  """
55
- require 'spec_helper'
52
+ The following mocks are not verified:
56
53
 
57
- describe 'Collaborator' do
58
- it "tests something", verifies_contract: 'Collaborator#some_method(SomeInput)=>SomeOutput' do
59
- # do nothing
60
- end
61
- end
54
+ 1. Collaborator#some_method(SomeInput)=>SomeOutput
62
55
  """
63
56
 
64
- When I run the test suite
65
- Then I should not see any output saying the stub is unverified
66
-
67
57
  Scenario: Stubbed doubles using hash syntax
68
58
  Given a test that uses VerifiedDouble to stub an object:
69
59
  """
@@ -79,16 +69,10 @@ Feature: 02. Verified stubs
79
69
  end
80
70
  """
81
71
 
82
- And the test suite has a contract test for the stub:
72
+ When I run the test suite
73
+ Then I should be informed that the mock is unverified:
83
74
  """
84
- require 'spec_helper'
75
+ The following mocks are not verified:
85
76
 
86
- describe 'Collaborator' do
87
- it "tests something", verifies_contract: 'Collaborator#some_method=>SomeOutput' do
88
- # do nothing
89
- end
90
- end
77
+ 1. Collaborator#some_method()=>SomeOutput
91
78
  """
92
-
93
- When I run the test suite
94
- Then I should not see any output saying the stub is unverified
@@ -12,6 +12,7 @@ require 'verified_double/method_signature/class_value'
12
12
  require 'verified_double/method_signature/rspec_double_value'
13
13
  require 'verified_double/method_signatures_report'
14
14
  require 'verified_double/parse_method_signature'
15
+ require 'verified_double/rspec_mocks_syntax_overrides'
15
16
  require 'verified_double/recorded_method_signature'
16
17
  require 'verified_double/recorded_method_signature_registry'
17
18
  require 'verified_double/simple_double'
@@ -26,7 +27,17 @@ module VerifiedDouble
26
27
  end
27
28
 
28
29
  def self.of_instance(*args)
29
- VerifiedDouble.record(double(*args))
30
+ d = double(*args)
31
+ simple_double = SimpleDouble.new(d)
32
+
33
+ if args[1]
34
+ args[1].each do |method, return_value|
35
+ method_signature = simple_double.build_recorded_method_signature(method)
36
+ method_signature.return_values = [MethodSignature::Value.from(return_value)]
37
+ VerifiedDouble.registry.insert 0, method_signature
38
+ end
39
+ end
40
+ VerifiedDouble.record(d)
30
41
  end
31
42
 
32
43
  def self.record(a_double)
@@ -1,6 +1,11 @@
1
1
  module VerifiedDouble
2
2
  class RecordedMethodSignature < MethodSignature
3
- attr_accessor :stack_frame
3
+ attr_reader :stack_frame
4
+
5
+ def initialize(*args)
6
+ @stack_frame = StackFrame.new(caller(0).detect{|line| line =~ /_spec\.rb/ })
7
+ super(*args)
8
+ end
4
9
 
5
10
  def to_s
6
11
  "#{super}\n # #{stack_frame}"
@@ -1,13 +1,14 @@
1
1
  module VerifiedDouble
2
2
  class RecordedMethodSignatureRegistry < Array
3
+ attr_accessor :current_double
4
+
3
5
  def add_method_signature(a_double, method)
4
6
  simple_double = SimpleDouble.new(a_double)
7
+ self << simple_double.build_recorded_method_signature(method)
8
+ end
5
9
 
6
- self << RecordedMethodSignature.new(
7
- class_name: simple_double.class_name,
8
- method_operator: simple_double.method_operator,
9
- method: method.to_s,
10
- stack_frame: StackFrame.new(caller(0).detect{|line| line =~ /_spec\.rb/ }))
10
+ def add_method_signature_with_current_double(method)
11
+ add_method_signature(current_double, method)
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,11 @@
1
+ RSpec.configure do |config|
2
+ config.include VerifiedDouble::Matchers
3
+
4
+ config.before do
5
+ self.extend VerifiedDouble::RSpecMocksSyntaxOverrides
6
+ end
7
+
8
+ config.after :suite do
9
+ VerifiedDouble.report_unverified_signatures(self)
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ module VerifiedDouble
2
+ module RSpecMocksSyntaxOverrides
3
+ def allow(*args)
4
+ if args[0].is_a?(VerifiedDouble::CanRecordInteractions)
5
+ VerifiedDouble.registry.current_double = args[0]
6
+ else
7
+ VerifiedDouble.registry.current_double = nil
8
+ end
9
+ super(*args)
10
+ end
11
+
12
+ def expect(*args)
13
+ if args[0].is_a?(VerifiedDouble::CanRecordInteractions)
14
+ VerifiedDouble.registry.current_double = args[0]
15
+ else
16
+ VerifiedDouble.registry.current_double = nil
17
+ end
18
+ super(*args)
19
+ end
20
+
21
+ def receive(*args)
22
+ if VerifiedDouble.registry.current_double
23
+ VerifiedDouble.registry.add_method_signature_with_current_double(args[0])
24
+ super(*args).tap {|result| result.extend(VerifiedDouble::CanRecordInteractions) }
25
+ else
26
+ super(*args)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -6,6 +6,14 @@ module VerifiedDouble
6
6
  @internal = internal
7
7
  end
8
8
 
9
+ def build_recorded_method_signature(method)
10
+ RecordedMethodSignature.new(
11
+ class_name: class_name,
12
+ method_operator: method_operator,
13
+ method: method.to_s)
14
+ end
15
+
16
+
9
17
  def class_name
10
18
  class_double? ? internal.name : internal.instance_variable_get('@name')
11
19
  end
@@ -1,3 +1,3 @@
1
1
  module VerifiedDouble
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'pry'
2
2
  require 'verified_double'
3
+ require 'verified_double/rspec_configuration'
3
4
 
4
5
  # This file was generated by the `rspec --init` command. Conventionally, all
5
6
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -17,8 +18,4 @@ RSpec.configure do |config|
17
18
  # the seed, which is printed after each run.
18
19
  # --seed 1234
19
20
  config.order = 'random'
20
-
21
- config.after :suite do
22
- VerifiedDouble.report_unverified_signatures(self)
23
- end
24
21
  end
@@ -17,14 +17,14 @@ describe VerifiedDouble::CanRecordInteractions do
17
17
 
18
18
  describe "#stub(method)" do
19
19
  it "appends a new method signature with the method to the registry", verifies_contract: 'Object#stubbed_fake_to_s()' do
20
- a_double.stub(:stubbed_fake_to_s)
20
+ allow(a_double).to receive(:stubbed_fake_to_s)
21
21
  expect(VerifiedDouble.registry.last.method).to eq('stubbed_fake_to_s')
22
22
  end
23
23
  end
24
24
 
25
25
  describe "#with(*args)" do
26
26
  it "sets the args of the last method signature", verifies_contract: 'Object#fake_to_s(Symbol, Symbol)' do
27
- a_double.should_receive(:fake_to_s).with(:arg_1, :arg_2)
27
+ expect(a_double).to receive(:fake_to_s).with(:arg_1, :arg_2)
28
28
 
29
29
  expect(VerifiedDouble.registry.last.args).to be_all{|arg| arg.is_a?(VerifiedDouble::MethodSignature::Value) }
30
30
  expect(VerifiedDouble.registry.last.args.map(&:content)).to eq([:arg_1, :arg_2])
@@ -35,7 +35,7 @@ describe VerifiedDouble::CanRecordInteractions do
35
35
 
36
36
  describe "#and_return(return_value)" do
37
37
  it "sets the return value of the last method signature", verifies_contract: 'Object#fake_to_s(Symbol, Symbol)=>Symbol' do
38
- a_double.should_receive(:fake_to_s).with(:arg_1, :arg_2).and_return(:return_value)
38
+ expect(a_double).to receive(:fake_to_s).with(:arg_1, :arg_2).and_return(:return_value)
39
39
 
40
40
  expect(VerifiedDouble.registry.last.return_values).to have(1).return_value
41
41
  expect(VerifiedDouble.registry.last.return_values.first).to be_a(VerifiedDouble::MethodSignature::Value)
@@ -15,28 +15,21 @@ 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, 'current_double' => nil, 'current_double=' => nil) }
20
+
18
21
  let(:verified_double_module){
19
22
  stub_const('VerifiedDouble', Class.new, transfer_nested_constants: true) }
20
23
 
21
- context "with multiple signatures in the registry" do
22
- it "sets the signatures from the registry" do
23
- verified_double_module
24
- .should_receive(:registry)
25
- .and_return([method_signature_1, method_signature_2])
26
-
27
- expect(subject.set_registered_signatures.registered_signatures.to_a).to eq(
28
- [method_signature_1, method_signature_2])
29
- end
30
- end
24
+ it "sets distinct signatures from the registry" do
25
+ verified_double_module
26
+ .should_receive(:registry)
27
+ .at_least(:once)
28
+ .and_return(registry)
31
29
 
32
- context "with duplicate signatures" do
33
- it "returns distinct method signatures" do
34
- verified_double_module
35
- .should_receive(:registry)
36
- .and_return([method_signature_1, method_signature_1])
30
+ expect(registry).to receive(:uniq).and_return(registry)
37
31
 
38
- expect(subject.set_registered_signatures.registered_signatures).to eq([method_signature_1])
39
- end
32
+ expect(subject.set_registered_signatures.registered_signatures).to eq(registry)
40
33
  end
41
34
  end
42
35
 
@@ -66,13 +59,13 @@ describe VerifiedDouble::MethodSignaturesReport do
66
59
  .stub_chain(:class, :descendant_filtered_examples)
67
60
  .and_return([example_with_verified_contract_tag, example_without_verified_contract_tag])
68
61
 
69
- parse_method_signature_service_class
70
- .should_receive(:new)
62
+ expect(parse_method_signature_service_class)
63
+ .to receive(:new)
71
64
  .with(example_with_verified_contract_tag.metadata[:verifies_contract])
72
65
  .and_return(parse_method_signature_service)
73
66
 
74
- parse_method_signature_service
75
- .should_receive(:execute)
67
+ expect(parse_method_signature_service)
68
+ .to receive(:execute)
76
69
  .and_return(method_signature)
77
70
 
78
71
  expect(subject.verified_signatures_from_tags).to eq([method_signature])
@@ -83,14 +76,14 @@ describe VerifiedDouble::MethodSignaturesReport do
83
76
  .stub_chain(:class, :descendant_filtered_examples)
84
77
  .and_return([example_with_verified_contract_tag, example_with_verified_contract_tag])
85
78
 
86
- parse_method_signature_service_class
87
- .should_receive(:new)
79
+ expect(parse_method_signature_service_class)
80
+ .to receive(:new)
88
81
  .with(example_with_verified_contract_tag.metadata[:verifies_contract])
89
82
  .at_least(:once)
90
83
  .and_return(parse_method_signature_service)
91
84
 
92
- parse_method_signature_service
93
- .should_receive(:execute)
85
+ expect(parse_method_signature_service)
86
+ .to receive(:execute)
94
87
  .and_return(method_signature)
95
88
 
96
89
  expect(subject.verified_signatures_from_tags).to eq([method_signature])
@@ -168,7 +161,7 @@ describe VerifiedDouble::MethodSignaturesReport do
168
161
  "2. #{unverified_signatures[1].recommended_verified_signature}",
169
162
  "For more info, check out https://www.relishapp.com/gsmendoza/verified-double." ]
170
163
 
171
- subject.should_receive(:puts).with(lines.join("\n\n"))
164
+ expect(subject).to receive(:puts).with(lines.join("\n\n"))
172
165
  subject.output_unverified_signatures
173
166
  end
174
167
  end
@@ -180,9 +173,17 @@ describe VerifiedDouble::MethodSignaturesReport do
180
173
 
181
174
  let(:method_signature) { VerifiedDouble::MethodSignature.new }
182
175
 
176
+ let(:registry){
177
+ double(:registry, 'current_double' => nil, 'current_double=' => nil) }
178
+
183
179
  it "works" do
184
180
  verified_double_module
185
- .should_receive(:verified_signatures_from_matchers)
181
+ .should_receive(:registry)
182
+ .at_least(:once)
183
+ .and_return(registry)
184
+
185
+ expect(verified_double_module)
186
+ .to receive(:verified_signatures_from_matchers)
186
187
  .and_return([method_signature])
187
188
 
188
189
  expect(subject.set_verified_signatures_from_matchers.verified_signatures_from_matchers)
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe VerifiedDouble::RecordedMethodSignatureRegistry do
4
+ let(:class_name){ 'Object' }
5
+ let(:a_double){ double(class_name) }
6
+ let(:method){ :fake_to_s }
7
+
4
8
  describe "#add_method_signature(a_double, method)" do
5
- let(:class_name){ 'Object' }
6
- let(:a_double){ double(class_name) }
7
- let(:method){ :fake_to_s }
8
-
9
- it "adds a method signture matching the method to itself" do
9
+ it "adds a method signature for the method of the double" do
10
10
  expect(subject).to be_empty
11
11
 
12
12
  subject.add_method_signature(a_double, method)
@@ -17,11 +17,21 @@ describe VerifiedDouble::RecordedMethodSignatureRegistry do
17
17
  expect(method_signature.method_operator).to eq('#')
18
18
  expect(method_signature.method).to eq(method.to_s)
19
19
  end
20
+ end
20
21
 
21
- it "records the stack frames of the double's caller" do
22
- subject.add_method_signature(a_double, method)
23
- expect(subject.first.stack_frame.to_s)
24
- .to include("./spec/verified_double/recorded_method_signature_registry_spec.rb")
22
+ describe "#add_method_signature_with_current_double(method)" do
23
+ it "adds a method signature for the method of the current double" do
24
+ subject.current_double = a_double
25
+
26
+ expect(subject).to be_empty
27
+
28
+ subject.add_method_signature_with_current_double(method)
29
+
30
+ expect(subject).to have(1).method_signature
31
+ method_signature = subject[0]
32
+ expect(method_signature.class_name).to eq(class_name)
33
+ expect(method_signature.method_operator).to eq('#')
34
+ expect(method_signature.method).to eq(method.to_s)
25
35
  end
26
36
  end
27
37
  end
@@ -4,12 +4,9 @@ describe VerifiedDouble::RecordedMethodSignature do
4
4
  class Dummy
5
5
  end
6
6
 
7
- let(:stack_frame_string){ "./lib/verified_double/method_signature.rb:7:in `block in initialize'" }
8
-
9
7
  let(:attributes){
10
8
  { class_name: 'Dummy',
11
- method_operator: '#',
12
- stack_frame: VerifiedDouble::StackFrame.new(stack_frame_string) } }
9
+ method_operator: '#' } }
13
10
 
14
11
  subject {
15
12
  described_class.new(attributes).tap {|method_signature|
@@ -17,7 +14,14 @@ describe VerifiedDouble::RecordedMethodSignature do
17
14
 
18
15
  describe "#to_s" do
19
16
  it "includes the stack frame" do
20
- expect(subject.to_s).to include(stack_frame_string)
17
+ expect(subject.to_s).to include(subject.stack_frame.to_s)
18
+ end
19
+ end
20
+
21
+ describe "#initialize" do
22
+ it "set the stack frame of the signature's caller" do
23
+ expect(subject.stack_frame.to_s)
24
+ .to include("./spec/verified_double/recorded_method_signature_spec.rb")
21
25
  end
22
26
  end
23
27
  end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe VerifiedDouble::RSpecMocksSyntaxOverrides do
4
+ let(:some_method){ 'fake_to_s' }
5
+ let(:some_result){ 'result' }
6
+
7
+ describe "#expect(*args)" do
8
+ context "where the double arg records VerifiedDouble interactions" do
9
+ let(:a_double) { VerifiedDouble.of_instance('Object') }
10
+
11
+ it "sets the registry's current_double to the first arg", verifies_contract: 'Object#fake_to_s()=>String' do
12
+ expect(VerifiedDouble.registry.current_double).to_not eq(a_double)
13
+ expect(a_double)
14
+ VerifiedDouble.registry.current_double.should eq(a_double)
15
+ end
16
+ end
17
+
18
+ context "where the double arg does not record VerifiedDouble interactions" do
19
+ let(:a_double) { double('Object') }
20
+
21
+ it "doesn't set the registry's current_double" do
22
+ expect(VerifiedDouble.registry.current_double).to_not equal(a_double)
23
+ expect(a_double)
24
+ expect(VerifiedDouble.registry.current_double).to be_nil
25
+ end
26
+ end
27
+ end
28
+
29
+ describe "#allow(*args)" do
30
+ context "where the double arg records VerifiedDouble interactions" do
31
+ let(:a_double) { VerifiedDouble.of_instance('Object') }
32
+
33
+ it "sets the registry's current_double to the first arg", verifies_contract: 'Object#fake_to_s()=>String' do
34
+ expect(VerifiedDouble.registry.last).to_not eq(a_double)
35
+ allow(a_double)
36
+ VerifiedDouble.registry.current_double.should eq(a_double)
37
+ end
38
+ end
39
+
40
+ context "where the double arg does not record VerifiedDouble interactions" do
41
+ let(:a_double) { double('Object') }
42
+
43
+ it "clears registry's current_double" do
44
+ expect(VerifiedDouble.registry.current_double).to_not equal(a_double)
45
+ allow(a_double)
46
+ expect(VerifiedDouble.registry.current_double).to be_nil
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "#receive(*args)" do
52
+ context "where the current double is recording VerifiedDouble interactions" do
53
+ let(:a_double) { VerifiedDouble.of_instance('Object') }
54
+
55
+ it "adds the first arg as a method signature for the current double" do
56
+ expect(a_double).to receive(some_method).and_return(some_result)
57
+
58
+ method_signature = VerifiedDouble.registry.last
59
+ expect(method_signature).to be_a(VerifiedDouble::MethodSignature)
60
+ expect(method_signature.method).to eq(some_method)
61
+ expect(method_signature.return_values.map(&:content)).to eq([some_result])
62
+
63
+ a_double.fake_to_s
64
+ end
65
+ end
66
+
67
+ context "where the current double is not recording VerifiedDouble interactions" do
68
+ let(:a_double) { double('Object') }
69
+
70
+ it "doesn't add a method signature for the method" do
71
+ registry_size = VerifiedDouble.registry.size
72
+ expect(a_double).to receive(some_method).and_return(some_result)
73
+
74
+ expect(VerifiedDouble.registry.size).to eq(registry_size)
75
+ a_double.fake_to_s
76
+ end
77
+ end
78
+ end
79
+ end
@@ -54,4 +54,16 @@ describe VerifiedDouble::SimpleDouble do
54
54
  end
55
55
  end
56
56
  end
57
+
58
+ describe "#build_record_method_signature(method)" do
59
+ let(:method){ :fake_to_s }
60
+ subject { simple_instance_double.build_recorded_method_signature(method) }
61
+
62
+ it "returns a method signature for the method of the double" do
63
+ expect(subject).to be_a(VerifiedDouble::RecordedMethodSignature)
64
+ expect(subject.class_name).to eq(class_name)
65
+ expect(subject.method_operator).to eq('#')
66
+ expect(subject.method).to eq(method.to_s)
67
+ end
68
+ end
57
69
  end
@@ -48,6 +48,33 @@ describe VerifiedDouble do
48
48
  it "stubs the methods of the instance" do
49
49
  expect(subject.send(stubbed_method)).to eq(assumed_output)
50
50
  end
51
+
52
+ it "inserts a new method signature with the method as the FIRST item of the registry" do
53
+ # so that it doesn't interfere with the current VerifiedDouble.registry.last
54
+ subject
55
+ expect(VerifiedDouble.registry.first).to be_a(VerifiedDouble::RecordedMethodSignature)
56
+ expect(VerifiedDouble.registry.first.method).to eq(stubbed_method.to_s)
57
+ end
58
+
59
+ context "where the double is an value of an expectation" do
60
+ let(:parent){ VerifiedDouble.of_instance('Object') }
61
+ let(:parent_method){ :parent_method }
62
+ let(:parent_output){ :parent_output }
63
+
64
+ it "should not interfere with the method signature recording of the expectation", verifies_contract: 'Object#parent_method(Object)=>Symbol' do
65
+ expect(parent).to receive(parent_method).with(subject).and_return(parent_output)
66
+
67
+ parent_method_signature =
68
+ VerifiedDouble.registry
69
+ .select{|s|
70
+ s.args[0].try(:content) == subject &&
71
+ s.return_values[0].try(:content) == parent_output }
72
+
73
+ expect(parent_method_signature).to be_present
74
+
75
+ parent.send(:parent_method, subject)
76
+ end
77
+ end
51
78
  end
52
79
  end
53
80
 
@@ -79,7 +106,7 @@ describe VerifiedDouble do
79
106
  .stub_chain(:class, :descendant_filtered_examples)
80
107
  .and_return([])
81
108
 
82
- method_signatures_report_class.should_receive(:new).and_return(method_signatures_report)
109
+ expect(method_signatures_report_class).to receive(:new).and_return(method_signatures_report)
83
110
 
84
111
  actions = [
85
112
  :set_registered_signatures,
@@ -90,8 +117,8 @@ describe VerifiedDouble do
90
117
  :output_unverified_signatures]
91
118
 
92
119
  actions.each do |action|
93
- method_signatures_report
94
- .should_receive(action)
120
+ expect(method_signatures_report)
121
+ .to receive(action)
95
122
  .and_return(method_signatures_report)
96
123
  end
97
124
 
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: verified_double
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - George Mendoza
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -128,6 +128,8 @@ files:
128
128
  - lib/verified_double/parse_method_signature.rb
129
129
  - lib/verified_double/recorded_method_signature.rb
130
130
  - lib/verified_double/recorded_method_signature_registry.rb
131
+ - lib/verified_double/rspec_configuration.rb
132
+ - lib/verified_double/rspec_mocks_syntax_overrides.rb
131
133
  - lib/verified_double/simple_double.rb
132
134
  - lib/verified_double/stack_frame.rb
133
135
  - lib/verified_double/version.rb
@@ -144,6 +146,7 @@ files:
144
146
  - spec/verified_double/parse_method_signature_spec.rb
145
147
  - spec/verified_double/recorded_method_signature_registry_spec.rb
146
148
  - spec/verified_double/recorded_method_signature_spec.rb
149
+ - spec/verified_double/rspec_mocks_syntax_overrides_spec.rb
147
150
  - spec/verified_double/simple_double_spec.rb
148
151
  - spec/verified_double/stack_frame_spec.rb
149
152
  - spec/verified_double_spec.rb
@@ -196,6 +199,7 @@ test_files:
196
199
  - spec/verified_double/parse_method_signature_spec.rb
197
200
  - spec/verified_double/recorded_method_signature_registry_spec.rb
198
201
  - spec/verified_double/recorded_method_signature_spec.rb
202
+ - spec/verified_double/rspec_mocks_syntax_overrides_spec.rb
199
203
  - spec/verified_double/simple_double_spec.rb
200
204
  - spec/verified_double/stack_frame_spec.rb
201
205
  - spec/verified_double_spec.rb