verified_double 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,33 @@
1
+ 0.4.3 - 2013-10-22
2
+ ------------------
3
+
4
+ * [#26] Allow class to be passed to `of_instance` and `of_class`.
5
+
1
6
  0.4.2 - 2013-09-28
2
7
  ------------------
3
8
 
4
- [#25] Fix: cannot mock is_a? on a VerifiedDouble instance double.
9
+ * [#25] Fix: cannot mock is_a? on a VerifiedDouble instance double.
5
10
 
6
11
  0.4.1 - 2013-08-17
7
12
  ------------------
8
13
 
9
- [#20] Fix: Cannot get stack frame of method signature recorded within a shared example.
14
+ * [#20] Fix: Cannot get stack frame of method signature recorded within a shared example.
10
15
 
11
- [#21] Fix: Class double return value cannot be verified.
16
+ * [#21] Fix: Class double return value cannot be verified.
12
17
 
13
18
  0.4.0 - 2013-07-28
14
19
  ------------------
15
20
 
16
- [#7] Pass: I should be able to use the RSpec's new expect syntax with
21
+ * [#7] Pass: I should be able to use the RSpec's new expect syntax with
17
22
  VerifiedDouble.
18
23
 
19
- [#7] Require verified_double/rspec_configuration in order to integrate
24
+ * [#7] Require verified_double/rspec_configuration in order to integrate
20
25
  verified_double with rspec.
21
26
 
22
- [#18] Fix Scenario: stubbed doubles using hash syntax are no longer being
27
+ * [#18] Fix Scenario: stubbed doubles using hash syntax are no longer being
23
28
  recorded after 0.3.0.
24
29
 
25
- [#19] Ensure: if `VerifiedDouble.of_instance(class_name, method_stubs={})` is
30
+ * [#19] Ensure: if `VerifiedDouble.of_instance(class_name, method_stubs={})` is
26
31
  used a argument or return value value of an expectation, then it should
27
32
  not interfere with the method signature recording of the expectation.
28
33
 
data/README.md CHANGED
@@ -56,4 +56,4 @@ Caveats
56
56
  Special thanks
57
57
  --------------
58
58
 
59
- To [Thomas Sinclair](https://twitter.com/anathematic) of [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 initially sponsoring this gem.
@@ -1,28 +1,33 @@
1
+ 0.4.3 - 2013-10-22
2
+ ------------------
3
+
4
+ * [#26] Allow class to be passed to `of_instance` and `of_class`.
5
+
1
6
  0.4.2 - 2013-09-28
2
7
  ------------------
3
8
 
4
- [#25] Fix: cannot mock is_a? on a VerifiedDouble instance double.
9
+ * [#25] Fix: cannot mock is_a? on a VerifiedDouble instance double.
5
10
 
6
11
  0.4.1 - 2013-08-17
7
12
  ------------------
8
13
 
9
- [#20] Fix: Cannot get stack frame of method signature recorded within a shared example.
14
+ * [#20] Fix: Cannot get stack frame of method signature recorded within a shared example.
10
15
 
11
- [#21] Fix: Class double return value cannot be verified.
16
+ * [#21] Fix: Class double return value cannot be verified.
12
17
 
13
18
  0.4.0 - 2013-07-28
14
19
  ------------------
15
20
 
16
- [#7] Pass: I should be able to use the RSpec's new expect syntax with
21
+ * [#7] Pass: I should be able to use the RSpec's new expect syntax with
17
22
  VerifiedDouble.
18
23
 
19
- [#7] Require verified_double/rspec_configuration in order to integrate
24
+ * [#7] Require verified_double/rspec_configuration in order to integrate
20
25
  verified_double with rspec.
21
26
 
22
- [#18] Fix Scenario: stubbed doubles using hash syntax are no longer being
27
+ * [#18] Fix Scenario: stubbed doubles using hash syntax are no longer being
23
28
  recorded after 0.3.0.
24
29
 
25
- [#19] Ensure: if `VerifiedDouble.of_instance(class_name, method_stubs={})` is
30
+ * [#19] Ensure: if `VerifiedDouble.of_instance(class_name, method_stubs={})` is
26
31
  used a argument or return value value of an expectation, then it should
27
32
  not interfere with the method signature recording of the expectation.
28
33
 
@@ -56,4 +56,4 @@ Caveats
56
56
  Special thanks
57
57
  --------------
58
58
 
59
- To [Thomas Sinclair](https://twitter.com/anathematic) of [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 initially sponsoring this gem.
@@ -67,6 +67,36 @@ Feature: 01. Verified mocks
67
67
  When I run the test suite
68
68
  Then I should not see any output saying the mock is unverified
69
69
 
70
+ Scenario: Instantiating an instance double with a class argument
71
+ Given a test that uses VerifiedDouble to mock an object:
72
+ """
73
+ require 'spec_helper'
74
+ describe ObjectUnderTest do
75
+ let(:input) { SomeInput.new }
76
+ let(:output) { SomeOutput.new }
77
+ let(:instance_double) { VerifiedDouble.of_instance(Collaborator) }
78
+
79
+ it "tests something" do
80
+ expect(instance_double).to receive(:some_method).with(input).and_return(output)
81
+ ObjectUnderTest.new.do_something(instance_double, input)
82
+ end
83
+ end
84
+ """
85
+
86
+ And the test suite has a contract test for the mock:
87
+ """
88
+ require 'spec_helper'
89
+
90
+ describe 'Collaborator' do
91
+ it "tests something", verifies_contract: 'Collaborator#some_method(SomeInput)=>SomeOutput' do
92
+ # do nothing
93
+ end
94
+ end
95
+ """
96
+
97
+ When I run the test suite
98
+ Then I should not see any output saying the mock is unverified
99
+
70
100
  Scenario: Unverified instance doubles
71
101
  Given a test that uses VerifiedDouble to mock an object:
72
102
  """
@@ -122,6 +152,36 @@ Feature: 01. Verified mocks
122
152
  When I run the test suite
123
153
  Then I should not see any output saying the mock is unverified
124
154
 
155
+ Scenario: Instantiating a class double with a class argument
156
+ Given a test that uses VerifiedDouble to mock a class:
157
+ """
158
+ require 'spec_helper'
159
+ describe ObjectUnderTest do
160
+ let(:input) { SomeInput.new }
161
+ let(:output) { SomeOutput.new }
162
+ let(:class_double) { VerifiedDouble.of_class(Collaborator) }
163
+
164
+ it "tests something" do
165
+ expect(class_double).to receive(:some_method).with(input).and_return(output)
166
+ ObjectUnderTest.do_something(input)
167
+ end
168
+ end
169
+ """
170
+
171
+ And the test suite has a contract test for the mock:
172
+ """
173
+ require 'spec_helper'
174
+
175
+ describe 'Collaborator' do
176
+ it "tests something", verifies_contract: 'Collaborator.some_method(SomeInput)=>SomeOutput' do
177
+ # do nothing
178
+ end
179
+ end
180
+ """
181
+
182
+ When I run the test suite
183
+ Then I should not see any output saying the mock is unverified
184
+
125
185
  Scenario: Unverified class doubles
126
186
  Given a test that uses VerifiedDouble to mock an object:
127
187
  """
@@ -23,9 +23,9 @@ require 'verified_double/stack_frame'
23
23
  module VerifiedDouble
24
24
  extend RSpec::Mocks::ExampleMethods
25
25
 
26
- def self.of_class(class_name, options = {})
26
+ def self.of_class(class_value, options = {})
27
27
  options[:transfer_nested_constants] = true if options[:transfer_nested_constants].nil?
28
- d = stub_const(class_name, Class.new, options)
28
+ d = stub_const(class_value.to_s, Class.new, options)
29
29
  d.extend(VerifiedDouble::IsAClassDouble)
30
30
  VerifiedDouble.record(d)
31
31
  end
@@ -15,7 +15,7 @@ module VerifiedDouble
15
15
 
16
16
 
17
17
  def class_name
18
- class_double? ? internal.name : internal.instance_variable_get('@name')
18
+ class_double? ? internal.name : internal.instance_variable_get('@name').to_s
19
19
  end
20
20
 
21
21
  def class_double?
@@ -1,3 +1,3 @@
1
1
  module VerifiedDouble
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -24,6 +24,14 @@ describe VerifiedDouble::SimpleDouble do
24
24
  end
25
25
  end
26
26
 
27
+ context "where the internal double is a double with a class value" do
28
+ let(:some_instance_double) { VerifiedDouble.of_instance(Dummy) }
29
+
30
+ it "is the name of the class represented by the double" do
31
+ expect(simple_instance_double.class_name).to eq('Dummy')
32
+ end
33
+ end
34
+
27
35
  context "where the internal double is a stub const" do
28
36
  it "is the name of the class represented by the class double" do
29
37
  expect(simple_class_double.class_name).to eq(class_name)
@@ -60,7 +60,7 @@ describe VerifiedDouble do
60
60
  let(:parent){ VerifiedDouble.of_instance('Object') }
61
61
  let(:parent_method){ :parent_method }
62
62
  let(:parent_output){ :parent_output }
63
-
63
+
64
64
  it "should not interfere with the method signature recording of the expectation", verifies_contract: 'Object#parent_method(Object)=>Symbol' do
65
65
  expect(parent).to receive(parent_method).with(subject).and_return(parent_output)
66
66
 
@@ -92,6 +92,15 @@ describe VerifiedDouble do
92
92
  subject = described_class.of_class(class_name)
93
93
  expect(subject).to eq(class_name.constantize)
94
94
  end
95
+
96
+ context "where the argument is a class" do
97
+ let(:argument) { Object }
98
+
99
+ it "returns the double" do
100
+ subject = described_class.of_class(argument)
101
+ expect(subject.name).to eq(argument.name)
102
+ end
103
+ end
95
104
  end
96
105
 
97
106
  describe ".report_unverified_signatures" do
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: verified_double
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.2
5
+ version: 0.4.3
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-09-28 00:00:00.000000000 Z
12
+ date: 2013-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime