verified_double 0.1.1 → 0.2.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.
Files changed (41) hide show
  1. data/CHANGELOG.markdown +12 -0
  2. data/README.md +25 -14
  3. data/features/CHANGELOG.markdown +12 -0
  4. data/features/readme.md +25 -14
  5. data/features/verified_mocks.feature +4 -2
  6. data/lib/verified_double.rb +10 -1
  7. data/lib/verified_double/matchers.rb +2 -2
  8. data/lib/verified_double/method_signature.rb +5 -5
  9. data/lib/verified_double/method_signature/boolean_value.rb +9 -0
  10. data/lib/verified_double/method_signature/class_value.rb +17 -0
  11. data/lib/verified_double/method_signature/instance_double_value.rb +9 -0
  12. data/lib/verified_double/method_signature/instance_value.rb +17 -0
  13. data/lib/verified_double/method_signature/recording_double_class_value.rb +9 -0
  14. data/lib/verified_double/method_signature/rspec_double_value.rb +9 -0
  15. data/lib/verified_double/method_signature/value.rb +37 -0
  16. data/lib/verified_double/method_signatures_report.rb +10 -3
  17. data/lib/verified_double/parse_method_signature.rb +2 -2
  18. data/lib/verified_double/recorded_method_signature.rb +9 -0
  19. data/lib/verified_double/recording_double.rb +13 -4
  20. data/lib/verified_double/stack_frame.rb +11 -0
  21. data/lib/verified_double/version.rb +1 -1
  22. data/spec/spec_helper.rb +1 -0
  23. data/spec/verified_double/matchers_spec.rb +1 -1
  24. data/spec/verified_double/method_signature/boolean_value_spec.rb +11 -0
  25. data/spec/verified_double/method_signature/class_value_spec.rb +35 -0
  26. data/spec/verified_double/method_signature/instance_double_value_spec.rb +17 -0
  27. data/spec/verified_double/method_signature/instance_value_spec.rb +39 -0
  28. data/spec/verified_double/method_signature/recording_double_class_value_spec.rb +23 -0
  29. data/spec/verified_double/method_signature/rspec_double_spec.rb +14 -0
  30. data/spec/verified_double/method_signature/value_spec.rb +89 -0
  31. data/spec/verified_double/method_signature_spec.rb +16 -16
  32. data/spec/verified_double/method_signatures_report_spec.rb +14 -12
  33. data/spec/verified_double/parse_method_signature_spec.rb +3 -3
  34. data/spec/verified_double/recorded_method_signature_spec.rb +23 -0
  35. data/spec/verified_double/recording_double_spec.rb +103 -77
  36. data/spec/verified_double/stack_frame_spec.rb +15 -0
  37. data/spec/verified_double_spec.rb +1 -1
  38. metadata +29 -7
  39. data/lib/verified_double/method_signature_value.rb +0 -45
  40. data/spec/unit_helper.rb +0 -16
  41. data/spec/verified_double/method_signature_value_spec.rb +0 -126
@@ -0,0 +1,11 @@
1
+ module VerifiedDouble
2
+ class StackFrame
3
+ def initialize(string)
4
+ @string = string
5
+ end
6
+
7
+ def to_s
8
+ @string.gsub(%r{.*/spec/}, "./spec/")
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module VerifiedDouble
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require 'pry'
1
2
  require 'verified_double'
2
3
 
3
4
  # This file was generated by the `rspec --init` command. Conventionally, all
@@ -1,4 +1,4 @@
1
- require 'unit_helper'
1
+ require 'spec_helper'
2
2
  require 'verified_double/matchers'
3
3
 
4
4
  describe VerifiedDouble::Matchers do
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe VerifiedDouble::MethodSignature::BooleanValue do
4
+ subject { described_class.new(true) }
5
+
6
+ describe "#content_class" do
7
+ it "should be VerifiedDouble::Boolean" do
8
+ expect(subject.content_class).to eq(VerifiedDouble::Boolean)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe VerifiedDouble::MethodSignature::ClassValue do
4
+ subject { described_class.new(String) }
5
+
6
+ describe "#belongs_to?(other)" do
7
+ context "where the value and other have the same content" do
8
+ let(:other) { described_class.new(String) }
9
+ it { expect(subject.belongs_to?(other)).to be_true }
10
+ end
11
+
12
+ context "where the value and other do not have the same content" do
13
+ let(:other) { described_class.new(Object) }
14
+ it { expect(subject.belongs_to?(other)).to be_false }
15
+ end
16
+ end
17
+
18
+ describe "#content_as_instance" do
19
+ context "where the value is a class which can be initialized" do
20
+ subject { described_class.new(String) }
21
+
22
+ it "returns the initialized instance of the value " do
23
+ expect(subject.content_as_instance).to eq(String.new)
24
+ end
25
+ end
26
+
27
+ context "where the value is a class which cannot be initialized" do
28
+ subject { described_class.new(Integer) }
29
+
30
+ it "returns an object" do
31
+ expect(subject.content_as_instance).to be_an(Object)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe VerifiedDouble::MethodSignature::InstanceDoubleValue do
4
+ class Item
5
+ end
6
+
7
+ let(:class_name){ 'Item' }
8
+ let(:some_instance_double){ double(class_name) }
9
+ let(:recording_instance_double) { VerifiedDouble::RecordingDouble.new(some_instance_double, class_name) }
10
+ subject { described_class.new(recording_instance_double) }
11
+
12
+ describe "#content_as_instance" do
13
+ it "is the equivalent content_as_instance of the content's class" do
14
+ expect(subject.content_as_instance).to be_a(Item)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe VerifiedDouble::MethodSignature::InstanceValue do
4
+ describe "#belongs_to?(other)" do
5
+ subject { this.belongs_to?(other) }
6
+
7
+ context "where the other value is an instance and self's value matches it" do
8
+ let(:this){ described_class.new(1) }
9
+ let(:other){ described_class.new(1) }
10
+ it { expect(subject).to be_true }
11
+ end
12
+
13
+ context "where the other value is an instance and self's value does not match it" do
14
+ let(:this){ described_class.new(2) }
15
+ let(:other){ described_class.new(1) }
16
+ it { expect(subject).to be_false }
17
+ end
18
+
19
+ context "where self is an instance and the other's class is an ancestor of self's modified class" do
20
+ let(:this){ described_class.new(1) }
21
+ let(:other){ VerifiedDouble::MethodSignature::ClassValue.new(Object) }
22
+ it { expect(subject).to be_true }
23
+ end
24
+
25
+ context "where self is an instance and the other's class is not an ancestor of self's modified class" do
26
+ let(:this){ described_class.new(1) }
27
+ let(:other){ VerifiedDouble::MethodSignature::ClassValue.new(Float) }
28
+ it { expect(subject).to be_false }
29
+ end
30
+ end
31
+
32
+ describe "#content_as_instance" do
33
+ subject { described_class.new(:some_value) }
34
+
35
+ it "returns the value" do
36
+ expect(subject.content_as_instance).to eq(:some_value)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe VerifiedDouble::MethodSignature::RecordingDoubleClassValue do
4
+ class Dummy
5
+ end
6
+
7
+ let(:class_name) { 'Dummy' }
8
+ let(:some_class_double) { stub_const(class_name, Class.new) }
9
+ let(:recording_class_double) { VerifiedDouble::RecordingDouble.new(some_class_double, class_name) }
10
+
11
+ subject { described_class.new(recording_class_double) }
12
+
13
+ describe "#belongs_to(other)" do
14
+ context "where the doubled class of the recording double belongs to the other value" do
15
+ it { expect(subject.belongs_to?(VerifiedDouble::MethodSignature::ClassValue.new(Dummy))).to be_true }
16
+ end
17
+
18
+ context "where the doubled class of the recording double does not belong to the other value" do
19
+ it { expect(subject.belongs_to?(VerifiedDouble::MethodSignature::ClassValue.new(Object))).to be_false }
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe VerifiedDouble::MethodSignature::RspecDoubleValue do
4
+ let(:rspec_double) { double('Object') }
5
+ subject { described_class.new(rspec_double) }
6
+
7
+ describe "#content_class" do
8
+ context "where the value is a double" do
9
+ it "is the class represented by the class_name of the recording double" do
10
+ expect(subject.content_class).to eq(Object)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ require 'verified_double/method_signature/value'
3
+
4
+ describe VerifiedDouble::MethodSignature::Value do
5
+ class Dummy
6
+ end
7
+
8
+ let(:class_name){ 'Dummy' }
9
+
10
+ let(:value){ :some_value }
11
+
12
+ describe ".from(content)" do
13
+ subject { described_class.from(content) }
14
+
15
+ context "where content is true" do
16
+ let(:content) { true }
17
+ it { expect(subject).to be_a(VerifiedDouble::MethodSignature::BooleanValue) }
18
+ end
19
+
20
+ context "where content is false" do
21
+ let(:content) { false }
22
+ it { expect(subject).to be_a(VerifiedDouble::MethodSignature::BooleanValue) }
23
+ end
24
+
25
+ context "where content is a class" do
26
+ let(:content) { String }
27
+ it { expect(subject).to be_a(VerifiedDouble::MethodSignature::ClassValue) }
28
+ end
29
+
30
+ context "where content is a module" do
31
+ let(:content) { VerifiedDouble }
32
+ it { expect(subject).to be_a(VerifiedDouble::MethodSignature::ClassValue) }
33
+ end
34
+
35
+ context "where content is an rspec mock" do
36
+ let(:content) { double(:stuff) }
37
+ it { expect(subject).to be_a(VerifiedDouble::MethodSignature::RspecDoubleValue) }
38
+ end
39
+
40
+ context "where content is an class recording double" do
41
+ let(:class_double){ stub_const(class_name, Class.new, transfer_nested_constants: true) }
42
+ let(:content) { VerifiedDouble::RecordingDouble.new(class_double, class_name) }
43
+
44
+ it { expect(subject).to be_a(VerifiedDouble::MethodSignature::RecordingDoubleClassValue) }
45
+ end
46
+
47
+ context "where content is an instance recording double" do
48
+ let(:some_instance_double){ double('Dummy') }
49
+ let(:content) { VerifiedDouble::RecordingDouble.new(some_instance_double, class_name) }
50
+
51
+ it { expect(subject).to be_a(VerifiedDouble::MethodSignature::InstanceDoubleValue) }
52
+ end
53
+
54
+ context "where content is an instance" do
55
+ let(:content) { :some_symbol }
56
+
57
+ it { expect(subject).to be_a(VerifiedDouble::MethodSignature::InstanceValue) }
58
+ end
59
+ end
60
+
61
+ describe "#content_class" do
62
+ subject { method_signature_value.content_class }
63
+
64
+ context "where the value is recording double" do
65
+ let(:recording_double){ VerifiedDouble.of_instance('Object') }
66
+ let(:method_signature_value) { described_class.new(recording_double) }
67
+
68
+ it "is the class represented by the class_name of the recording double" do
69
+ expect(subject).to eq(Object)
70
+ end
71
+ end
72
+
73
+ context "where the value is not true or false" do
74
+ let(:method_signature_value) { described_class.new(1) }
75
+ it "is the class of the value" do
76
+ expect(subject).to eq(Fixnum)
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "#recommended_value" do
82
+ subject { described_class.new(value) }
83
+
84
+ it "is a version of self that will be recommended to users to verify" do
85
+ expect(subject.recommended_value.content).to eq(subject.content_class)
86
+ expect(subject.recommended_value.content).to_not eq(subject)
87
+ end
88
+ end
89
+ end
@@ -1,4 +1,4 @@
1
- require 'unit_helper'
1
+ require 'spec_helper'
2
2
  require 'verified_double/method_signature'
3
3
 
4
4
  describe VerifiedDouble::MethodSignature do
@@ -21,7 +21,7 @@ describe VerifiedDouble::MethodSignature do
21
21
 
22
22
  context "when there are args" do
23
23
  it "includes the arg values in the result" do
24
- subject.args = [VerifiedDouble::MethodSignatureValue.new(1), VerifiedDouble::MethodSignatureValue.new({})]
24
+ subject.args = [VerifiedDouble::MethodSignature::Value.from(1), VerifiedDouble::MethodSignature::Value.from({})]
25
25
  expect(subject.to_s).to eq("Dummy#do_something(1, {})")
26
26
  end
27
27
  end
@@ -35,14 +35,14 @@ describe VerifiedDouble::MethodSignature do
35
35
 
36
36
  context "when there is a nil arg" do
37
37
  it "displays nil for the arg of the result" do
38
- subject.args = [VerifiedDouble::MethodSignatureValue.new(nil)]
38
+ subject.args = [VerifiedDouble::MethodSignature::Value.from(nil)]
39
39
  expect(subject.to_s).to eq("Dummy#do_something(nil)")
40
40
  end
41
41
  end
42
42
 
43
43
  context "where there is a return value" do
44
44
  it "displays the return value" do
45
- subject.return_values = [VerifiedDouble::MethodSignatureValue.new(true)]
45
+ subject.return_values = [VerifiedDouble::MethodSignature::Value.from(true)]
46
46
  expect(subject.to_s).to eq("Dummy#do_something()=>true")
47
47
  end
48
48
  end
@@ -70,16 +70,16 @@ describe VerifiedDouble::MethodSignature do
70
70
  it { expect([method_signature, method_signature_with_same_to_s].uniq == [method_signature]).to be_true }
71
71
  end
72
72
 
73
- describe "#accepts?(other)" do
73
+ describe "#belongs_to?(other)" do
74
74
  let(:method_signature){
75
75
  described_class.new(
76
76
  class_name: 'Dummy',
77
77
  method_operator: '.',
78
78
  method: 'find',
79
- args: [VerifiedDouble::MethodSignatureValue.new(1)],
80
- return_values: [VerifiedDouble::MethodSignatureValue.new(Dummy.new)]) }
79
+ args: [VerifiedDouble::MethodSignature::Value.from(1)],
80
+ return_values: [VerifiedDouble::MethodSignature::Value.from(Dummy.new)]) }
81
81
 
82
- subject { method_signature.accepts?(other) }
82
+ subject { method_signature.belongs_to?(other) }
83
83
 
84
84
  context "where self has same attributes as other" do
85
85
  let(:other){ method_signature.clone }
@@ -104,7 +104,7 @@ describe VerifiedDouble::MethodSignature do
104
104
  context "where self and other have different number of args" do
105
105
  let(:other){
106
106
  method_signature.clone.tap{|ms|
107
- ms.args = [VerifiedDouble::MethodSignatureValue.new(1), VerifiedDouble::MethodSignatureValue.new(2)] } }
107
+ ms.args = [VerifiedDouble::MethodSignature::Value.from(1), VerifiedDouble::MethodSignature::Value.from(2)] } }
108
108
 
109
109
  it { expect(subject).to be_false }
110
110
  end
@@ -112,7 +112,7 @@ describe VerifiedDouble::MethodSignature do
112
112
  context "where not all of self's args accept the args of other" do
113
113
  let(:other){
114
114
  method_signature.clone.tap{|ms|
115
- ms.args = [VerifiedDouble::MethodSignatureValue.new(2)] } }
115
+ ms.args = [VerifiedDouble::MethodSignature::Value.from(2)] } }
116
116
 
117
117
  it { expect(subject).to be_false }
118
118
  end
@@ -120,7 +120,7 @@ describe VerifiedDouble::MethodSignature do
120
120
  context "where self and other have different number of return values" do
121
121
  let(:other){
122
122
  method_signature.clone.tap{|ms|
123
- ms.return_values = [VerifiedDouble::MethodSignatureValue.new(1), VerifiedDouble::MethodSignatureValue.new(2)] } }
123
+ ms.return_values = [VerifiedDouble::MethodSignature::Value.from(1), VerifiedDouble::MethodSignature::Value.from(2)] } }
124
124
 
125
125
  it { expect(subject).to be_false }
126
126
  end
@@ -128,7 +128,7 @@ describe VerifiedDouble::MethodSignature do
128
128
  context "where not all of self's return values accept the return values of other" do
129
129
  let(:other){
130
130
  method_signature.clone.tap{|ms|
131
- ms.return_values = [VerifiedDouble::MethodSignatureValue.new(Symbol)] } }
131
+ ms.return_values = [VerifiedDouble::MethodSignature::Value.from(Symbol)] } }
132
132
 
133
133
  it { expect(subject).to be_false }
134
134
  end
@@ -140,14 +140,14 @@ describe VerifiedDouble::MethodSignature do
140
140
  class_name: 'Dummy',
141
141
  method_operator: '.',
142
142
  method: 'find',
143
- args: [VerifiedDouble::MethodSignatureValue.new(1)],
144
- return_values: [VerifiedDouble::MethodSignatureValue.new(Dummy.new)]) }
143
+ args: [VerifiedDouble::MethodSignature::Value.from(1)],
144
+ return_values: [VerifiedDouble::MethodSignature::Value.from(Dummy.new)]) }
145
145
 
146
146
  subject { method_signature.recommended_verified_signature }
147
147
 
148
148
  it "is a method signature that is recommended for the user to verify" do
149
- expect(subject.args[0].value).to eq(method_signature.args[0].recommended_value.value)
150
- expect(subject.return_values[0].value).to eq(method_signature.return_values[0].recommended_value.value)
149
+ expect(subject.args[0].content).to eq(method_signature.args[0].recommended_value.content)
150
+ expect(subject.return_values[0].content).to eq(method_signature.return_values[0].recommended_value.content)
151
151
  end
152
152
  end
153
153
  end
@@ -1,4 +1,4 @@
1
- require 'unit_helper'
1
+ require 'spec_helper'
2
2
  require 'verified_double'
3
3
  require 'verified_double/method_signatures_report'
4
4
 
@@ -114,7 +114,7 @@ describe VerifiedDouble::MethodSignaturesReport do
114
114
  class_name: 'Person',
115
115
  method: 'find',
116
116
  method_operator: '.',
117
- args: [VerifiedDouble::MethodSignatureValue.new(1)]) }
117
+ args: [VerifiedDouble::MethodSignature::Value.from(1)]) }
118
118
 
119
119
  let(:registered_signature_without_match) {
120
120
  VerifiedDouble::MethodSignature.new(
@@ -127,11 +127,11 @@ describe VerifiedDouble::MethodSignaturesReport do
127
127
  class_name: 'Person',
128
128
  method: 'find',
129
129
  method_operator: '.',
130
- args: [VerifiedDouble::MethodSignatureValue.new(Object)]) }
130
+ args: [VerifiedDouble::MethodSignature::Value.from(Object)]) }
131
131
 
132
132
  it "retains registered signatures that cannot accept any of the verified_signatures" do
133
- expect(registered_signature.accepts?(verified_signature)).to be_true
134
- expect(registered_signature_without_match.accepts?(verified_signature)).to be_false
133
+ expect(registered_signature.belongs_to?(verified_signature)).to be_true
134
+ expect(registered_signature_without_match.belongs_to?(verified_signature)).to be_false
135
135
 
136
136
  subject.registered_signatures = [registered_signature, registered_signature_without_match]
137
137
  subject.verified_signatures = [verified_signature]
@@ -151,14 +151,14 @@ describe VerifiedDouble::MethodSignaturesReport do
151
151
  class_name: 'Dummy',
152
152
  method_operator: '.',
153
153
  method: 'find',
154
- args: [VerifiedDouble::MethodSignatureValue.new(1)],
155
- return_values: [VerifiedDouble::MethodSignatureValue.new(Dummy.new)]),
154
+ args: [VerifiedDouble::MethodSignature::Value.from(1)],
155
+ return_values: [VerifiedDouble::MethodSignature::Value.from(Dummy.new)]),
156
156
  VerifiedDouble::MethodSignature.new(
157
157
  class_name: 'Dummy',
158
158
  method_operator: '.',
159
159
  method: 'where',
160
- args: [VerifiedDouble::MethodSignatureValue.new(id: 1)],
161
- return_values: [VerifiedDouble::MethodSignatureValue.new(Dummy.new)]) ] }
160
+ args: [VerifiedDouble::MethodSignature::Value.from(id: 1)],
161
+ return_values: [VerifiedDouble::MethodSignature::Value.from(Dummy.new)]) ] }
162
162
 
163
163
  context "where there are no unverified_signatures" do
164
164
  it "should not output anything" do
@@ -173,11 +173,13 @@ describe VerifiedDouble::MethodSignaturesReport do
173
173
  subject.unverified_signatures = unverified_signatures
174
174
 
175
175
  lines = [
176
+ nil,
176
177
  "The following mocks are not verified:",
177
- unverified_signatures[0].recommended_verified_signature,
178
- unverified_signatures[1].recommended_verified_signature ]
178
+ "1. #{unverified_signatures[0].recommended_verified_signature}",
179
+ "2. #{unverified_signatures[1].recommended_verified_signature}",
180
+ "For more info, check out https://www.relishapp.com/gsmendoza/verified-double." ]
179
181
 
180
- subject.should_receive(:puts).with(lines.join("\n"))
182
+ subject.should_receive(:puts).with(lines.join("\n\n"))
181
183
  subject.output_unverified_signatures
182
184
  end
183
185
  end
@@ -1,4 +1,4 @@
1
- require 'unit_helper'
1
+ require 'spec_helper'
2
2
  require 'verified_double/parse_method_signature'
3
3
 
4
4
  describe VerifiedDouble::ParseMethodSignature do
@@ -65,7 +65,7 @@ describe VerifiedDouble::ParseMethodSignature do
65
65
  let(:string){ "Class.method(:arg_1, :arg_2)" }
66
66
 
67
67
  it "builds method signature values from the evals of the args" do
68
- expect(subject.args.map(&:value)).to eq([:arg_1, :arg_2])
68
+ expect(subject.args.map(&:content)).to eq([:arg_1, :arg_2])
69
69
  end
70
70
  end
71
71
 
@@ -83,7 +83,7 @@ describe VerifiedDouble::ParseMethodSignature do
83
83
  describe "#return_values" do
84
84
  context "for Class.method=>:return_value" do
85
85
  let(:string){ "Class.method=>:return_value" }
86
- it { expect(subject.return_values.map(&:value)).to eq([:return_value]) }
86
+ it { expect(subject.return_values.map(&:content)).to eq([:return_value]) }
87
87
  end
88
88
 
89
89
  context "for Class.method" do