verified_double 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGELOG.markdown +8 -0
  2. data/README.md +21 -49
  3. data/features/CHANGELOG.markdown +8 -0
  4. data/features/accessor_method_contracts.feature +107 -0
  5. data/features/customizing_arguments_and_return_values.feature +2 -2
  6. data/features/readme.md +21 -49
  7. data/features/rspec_mock_compatibility.feature +230 -0
  8. data/features/step_definitions/verified_double_steps.rb +17 -0
  9. data/features/{verified_double.feature → verified_mocks.feature} +5 -6
  10. data/features/verified_stubs.feature +94 -0
  11. data/lib/verified_double.rb +25 -10
  12. data/lib/verified_double/matchers.rb +35 -0
  13. data/lib/verified_double/method_signature_value.rb +15 -1
  14. data/lib/verified_double/method_signatures_report.rb +55 -0
  15. data/lib/verified_double/recording_double.rb +33 -12
  16. data/lib/verified_double/relays_to_internal_double_returning_self.rb +12 -0
  17. data/lib/verified_double/version.rb +1 -1
  18. data/spec/spec_helper.rb +3 -4
  19. data/spec/unit_helper.rb +3 -2
  20. data/spec/verified_double/matchers_spec.rb +96 -0
  21. data/spec/verified_double/method_signature_value_spec.rb +35 -0
  22. data/spec/verified_double/method_signatures_report_spec.rb +214 -0
  23. data/spec/verified_double/parse_method_signature_spec.rb +5 -1
  24. data/spec/verified_double/recording_double_spec.rb +103 -30
  25. data/spec/verified_double_spec.rb +70 -7
  26. data/verified_double.gemspec +0 -2
  27. metadata +17 -38
  28. data/lib/verified_double/get_registered_signatures.rb +0 -11
  29. data/lib/verified_double/get_unverified_signatures.rb +0 -13
  30. data/lib/verified_double/get_verified_signatures.rb +0 -17
  31. data/lib/verified_double/output_unverified_signatures.rb +0 -18
  32. data/lib/verified_double/report_unverified_signatures.rb +0 -16
  33. data/lib/verified_double/verify_doubles_service.rb +0 -15
  34. data/spec/verified_double/get_registered_signatures_spec.rb +0 -42
  35. data/spec/verified_double/get_unverified_signatures_spec.rb +0 -52
  36. data/spec/verified_double/get_verified_signatures_spec.rb +0 -63
  37. data/spec/verified_double/output_unverified_signatures_spec.rb +0 -58
  38. data/spec/verified_double/report_unverified_signatures_spec.rb +0 -57
  39. data/spec/verified_double/verify_doubles_service_spec.rb +0 -24
@@ -3,9 +3,9 @@ require 'verified_double'
3
3
 
4
4
  describe VerifiedDouble do
5
5
  describe ".registry" do
6
- it "is a array by default" do
6
+ it "is a array", verifies_contract: 'VerifiedDouble.registry()=>Array' do
7
7
  registry = VerifiedDouble.registry
8
- expect(registry).to be_a(Array)
8
+ expect(registry).to be_an(Array)
9
9
  end
10
10
 
11
11
  it "is memoized" do
@@ -13,7 +13,18 @@ describe VerifiedDouble do
13
13
  end
14
14
  end
15
15
 
16
- describe ".of_instance(class_name)" do
16
+ describe ".verified_signatures_from_matchers" do
17
+ it "is an array", verifies_contract: 'VerifiedDouble.verified_signatures_from_matchers()=>Array' do
18
+ verified_signatures_from_matchers = VerifiedDouble.verified_signatures_from_matchers
19
+ expect(verified_signatures_from_matchers).to be_an(Array)
20
+ end
21
+
22
+ it "is memoized" do
23
+ expect(VerifiedDouble.verified_signatures_from_matchers).to equal(VerifiedDouble.verified_signatures_from_matchers)
24
+ end
25
+ end
26
+
27
+ describe ".of_instance(class_name, method_stubs={})" do
17
28
  let(:class_name){ 'Object' }
18
29
 
19
30
  let(:subject) { described_class.of_instance(class_name) }
@@ -25,9 +36,19 @@ describe VerifiedDouble do
25
36
  end
26
37
 
27
38
  it "adds the double to the registry" do
28
- described_class.registry.clear
29
39
  recording_double = subject
30
- expect(described_class.registry).to eq([recording_double])
40
+ expect(described_class.registry.last).to eq(recording_double)
41
+ end
42
+
43
+ context "with method_stubs hash", verifies_contract: 'Object#some_method()=>Symbol' do
44
+ let(:stubbed_method){ :some_method }
45
+ let(:assumed_output){ :some_output }
46
+
47
+ subject { described_class.of_instance(class_name, some_method: assumed_output) }
48
+
49
+ it "stubs the methods of the instance" do
50
+ expect(subject.send(stubbed_method)).to eq(assumed_output)
51
+ end
31
52
  end
32
53
  end
33
54
 
@@ -44,9 +65,51 @@ describe VerifiedDouble do
44
65
  end
45
66
 
46
67
  it "adds the double to the registry" do
47
- described_class.registry.clear
48
68
  recording_double = subject
49
- expect(described_class.registry).to eq([recording_double])
69
+ expect(described_class.registry.last).to eq(recording_double)
70
+ end
71
+
72
+ context "with methods hash", verifies_contract: 'Object.some_method()=>Symbol' do
73
+ let(:stubbed_method){ :some_method }
74
+ let(:assumed_output){ :some_output }
75
+
76
+ subject { described_class.of_class(class_name, some_method: assumed_output) }
77
+
78
+ it "stubs the methods of the class" do
79
+ expect(subject.send(stubbed_method)).to eq(assumed_output)
80
+ end
81
+ end
82
+ end
83
+
84
+ describe ".report_unverified_signatures" do
85
+ let(:nested_example_group) { double('nested_example_group') }
86
+ let(:method_signatures_report) { VerifiedDouble.of_instance('VerifiedDouble::MethodSignaturesReport') }
87
+ let(:method_signatures_report_class) {
88
+ VerifiedDouble.of_class('VerifiedDouble::MethodSignaturesReport') }
89
+
90
+
91
+ it "builds a method signatures report, determines unverified signatures, and ouputs them" do
92
+ nested_example_group
93
+ .stub_chain(:class, :descendant_filtered_examples)
94
+ .and_return([])
95
+
96
+ method_signatures_report_class.should_receive(:new).and_return(method_signatures_report)
97
+
98
+ actions = [
99
+ :set_registered_signatures,
100
+ :set_verified_signatures_from_tags,
101
+ :set_verified_signatures_from_matchers,
102
+ :merge_verified_signatures,
103
+ :identify_unverified_signatures,
104
+ :output_unverified_signatures]
105
+
106
+ actions.each do |action|
107
+ method_signatures_report
108
+ .should_receive(action)
109
+ .and_return(method_signatures_report)
110
+ end
111
+
112
+ described_class.report_unverified_signatures(nested_example_group)
50
113
  end
51
114
  end
52
115
  end
@@ -18,11 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_runtime_dependency "rspec"
21
- gem.add_runtime_dependency "rspec-fire", '~> 1.1.3'
22
21
 
23
22
  gem.add_development_dependency "aruba"
24
23
  gem.add_development_dependency "cucumber"
25
24
  gem.add_development_dependency "pry"
26
25
  gem.add_development_dependency "activesupport"
27
-
28
26
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: verified_double
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.1.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-06-22 00:00:00.000000000 Z
12
+ date: 2013-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -27,22 +27,6 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  name: rspec
30
- - !ruby/object:Gem::Dependency
31
- type: :runtime
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 1.1.3
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- version: 1.1.3
45
- name: rspec-fire
46
30
  - !ruby/object:Gem::Dependency
47
31
  type: :development
48
32
  requirement: !ruby/object:Gem::Requirement
@@ -122,36 +106,32 @@ files:
122
106
  - README.md
123
107
  - Rakefile
124
108
  - features/CHANGELOG.markdown
109
+ - features/accessor_method_contracts.feature
125
110
  - features/customizing_arguments_and_return_values.feature
126
111
  - features/readme.md
112
+ - features/rspec_mock_compatibility.feature
127
113
  - features/step_definitions/verified_double_steps.rb
128
114
  - features/support/requires.rb
129
- - features/verified_double.feature
115
+ - features/verified_mocks.feature
116
+ - features/verified_stubs.feature
130
117
  - lib/verified_double.rb
131
118
  - lib/verified_double/boolean.rb
132
- - lib/verified_double/get_registered_signatures.rb
133
- - lib/verified_double/get_unverified_signatures.rb
134
- - lib/verified_double/get_verified_signatures.rb
119
+ - lib/verified_double/matchers.rb
135
120
  - lib/verified_double/method_signature.rb
136
121
  - lib/verified_double/method_signature_value.rb
137
- - lib/verified_double/output_unverified_signatures.rb
122
+ - lib/verified_double/method_signatures_report.rb
138
123
  - lib/verified_double/parse_method_signature.rb
139
124
  - lib/verified_double/recording_double.rb
140
- - lib/verified_double/report_unverified_signatures.rb
141
- - lib/verified_double/verify_doubles_service.rb
125
+ - lib/verified_double/relays_to_internal_double_returning_self.rb
142
126
  - lib/verified_double/version.rb
143
127
  - spec/spec_helper.rb
144
128
  - spec/unit_helper.rb
145
- - spec/verified_double/get_registered_signatures_spec.rb
146
- - spec/verified_double/get_unverified_signatures_spec.rb
147
- - spec/verified_double/get_verified_signatures_spec.rb
129
+ - spec/verified_double/matchers_spec.rb
148
130
  - spec/verified_double/method_signature_spec.rb
149
131
  - spec/verified_double/method_signature_value_spec.rb
150
- - spec/verified_double/output_unverified_signatures_spec.rb
132
+ - spec/verified_double/method_signatures_report_spec.rb
151
133
  - spec/verified_double/parse_method_signature_spec.rb
152
134
  - spec/verified_double/recording_double_spec.rb
153
- - spec/verified_double/report_unverified_signatures_spec.rb
154
- - spec/verified_double/verify_doubles_service_spec.rb
155
135
  - spec/verified_double_spec.rb
156
136
  - verified_double.gemspec
157
137
  homepage: https://www.relishapp.com/gsmendoza/verified-double
@@ -181,22 +161,21 @@ summary: VerifiedDouble would record any mock made in the test suite. It would t
181
161
  verify if the mock is valid by checking if there is a test against it.
182
162
  test_files:
183
163
  - features/CHANGELOG.markdown
164
+ - features/accessor_method_contracts.feature
184
165
  - features/customizing_arguments_and_return_values.feature
185
166
  - features/readme.md
167
+ - features/rspec_mock_compatibility.feature
186
168
  - features/step_definitions/verified_double_steps.rb
187
169
  - features/support/requires.rb
188
- - features/verified_double.feature
170
+ - features/verified_mocks.feature
171
+ - features/verified_stubs.feature
189
172
  - spec/spec_helper.rb
190
173
  - spec/unit_helper.rb
191
- - spec/verified_double/get_registered_signatures_spec.rb
192
- - spec/verified_double/get_unverified_signatures_spec.rb
193
- - spec/verified_double/get_verified_signatures_spec.rb
174
+ - spec/verified_double/matchers_spec.rb
194
175
  - spec/verified_double/method_signature_spec.rb
195
176
  - spec/verified_double/method_signature_value_spec.rb
196
- - spec/verified_double/output_unverified_signatures_spec.rb
177
+ - spec/verified_double/method_signatures_report_spec.rb
197
178
  - spec/verified_double/parse_method_signature_spec.rb
198
179
  - spec/verified_double/recording_double_spec.rb
199
- - spec/verified_double/report_unverified_signatures_spec.rb
200
- - spec/verified_double/verify_doubles_service_spec.rb
201
180
  - spec/verified_double_spec.rb
202
181
  has_rdoc:
@@ -1,11 +0,0 @@
1
- module VerifiedDouble
2
- class GetRegisteredSignatures
3
- def initialize(double_registry)
4
- @double_registry = double_registry
5
- end
6
-
7
- def execute
8
- @double_registry.map(&:method_signatures).flatten.uniq
9
- end
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- module VerifiedDouble
2
- class GetUnverifiedSignatures
3
- def initialize(get_registered_signatures, get_verified_signatures)
4
- @get_registered_signatures, @get_verified_signatures = get_registered_signatures, get_verified_signatures
5
- end
6
-
7
- def execute
8
- @get_registered_signatures.execute.select{|registered_signature|
9
- @get_verified_signatures.execute.all?{|verified_signature|
10
- ! registered_signature.accepts?(verified_signature) } }
11
- end
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- module VerifiedDouble
2
- class GetVerifiedSignatures
3
- def initialize(nested_example_group)
4
- @nested_example_group = nested_example_group
5
- end
6
-
7
- def execute
8
- results = @nested_example_group
9
- .class
10
- .descendant_filtered_examples
11
- .map{|example| example.metadata[:verifies_contract] }
12
- .compact
13
- .uniq
14
- .map{|method_signature_string| ParseMethodSignature.new(method_signature_string).execute }
15
- end
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- module VerifiedDouble
2
- class OutputUnverifiedSignatures
3
- def initialize(get_unverified_signatures)
4
- @get_unverified_signatures = get_unverified_signatures
5
- end
6
-
7
- def execute
8
- if unverified_signatures.any?
9
- output = ["The following mocks are not verified:" ] + unverified_signatures.map(&:recommended_verified_signature)
10
- puts output.join("\n")
11
- end
12
- end
13
-
14
- def unverified_signatures
15
- @unverified_signatures ||= @get_unverified_signatures.execute
16
- end
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- module VerifiedDouble
2
- class ReportUnverifiedSignatures
3
- attr_accessor :double_registry, :nested_example_group
4
-
5
- def initialize(double_registry, nested_example_group)
6
- @double_registry, @nested_example_group = double_registry, nested_example_group
7
- end
8
-
9
- def execute
10
- VerifiedDouble::OutputUnverifiedSignatures.new(
11
- VerifiedDouble::GetUnverifiedSignatures.new(
12
- VerifiedDouble::GetRegisteredSignatures.new(double_registry),
13
- VerifiedDouble::GetVerifiedSignatures.new(nested_example_group))).execute
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- module VerifiedDouble
2
- class VerifyDoublesService
3
- def initialize(world)
4
- @world = world
5
- end
6
-
7
- def execute
8
- unverified_method_signatures = @world.unverified_method_signatures
9
- if unverified_method_signatures.any?
10
- output = ["The following mocks are not verified:" ] + unverified_method_signatures
11
- puts output.join("\n")
12
- end
13
- end
14
- end
15
- end
@@ -1,42 +0,0 @@
1
- require 'unit_helper'
2
- require 'verified_double/get_registered_signatures'
3
-
4
- describe VerifiedDouble::GetRegisteredSignatures do
5
- let(:method_signature_1) {
6
- VerifiedDouble::MethodSignature.new(class_name: 'Object', method_operator: '#', method: 'to_s') }
7
-
8
- let(:method_signature_2) {
9
- VerifiedDouble::MethodSignature.new(class_name: 'Object', method_operator: '#', method: 'inspect') }
10
-
11
- let(:recording_double_1) {
12
- fire_double('VerifiedDouble::RecordingDouble',
13
- method_signatures: [method_signature_1]) }
14
-
15
- let(:recording_double_2) {
16
- fire_double('VerifiedDouble::RecordingDouble',
17
- method_signatures: [method_signature_2]) }
18
-
19
- subject { described_class.new(double_registry) }
20
-
21
- describe "#execute" do
22
- context "with multiple recording doubles in the registry" do
23
- let(:double_registry){ [recording_double_1, recording_double_2] }
24
-
25
- it "maps and flattens the method signatures of the recording doubles" do
26
- expect(subject.execute).to eq([method_signature_1, method_signature_2])
27
- end
28
- end
29
-
30
- context "with recording doubles with duplicate signatures" do
31
- let(:recording_double_2) {
32
- fire_double('VerifiedDouble::RecordingDouble',
33
- method_signatures: [method_signature_1]) }
34
-
35
- let(:double_registry){ [recording_double_1, recording_double_2] }
36
-
37
- it "returns distinct method signatures" do
38
- expect(subject.execute).to eq([method_signature_1])
39
- end
40
- end
41
- end
42
- end
@@ -1,52 +0,0 @@
1
- require 'unit_helper'
2
- require 'verified_double/get_unverified_signatures'
3
-
4
- describe VerifiedDouble::GetUnverifiedSignatures do
5
- let(:get_registered_signatures_service){
6
- fire_double('VerifiedDouble::GetRegisteredSignatures') }
7
-
8
- let(:get_verified_signatures_service){
9
- fire_double('VerifiedDouble::GetVerifiedSignatures') }
10
-
11
- subject { described_class.new(get_registered_signatures_service, get_verified_signatures_service) }
12
-
13
- describe "#execute" do
14
- let(:registered_signature) {
15
- VerifiedDouble::MethodSignature.new(
16
- class_name: 'Person',
17
- method: 'find',
18
- method_operator: '.',
19
- args: [VerifiedDouble::MethodSignatureValue.new(1)]) }
20
-
21
- let(:registered_signature_without_match) {
22
- VerifiedDouble::MethodSignature.new(
23
- class_name: 'Person',
24
- method: 'save!',
25
- method_operator: '#') }
26
-
27
- let(:verified_signature) {
28
- VerifiedDouble::MethodSignature.new(
29
- class_name: 'Person',
30
- method: 'find',
31
- method_operator: '.',
32
- args: [VerifiedDouble::MethodSignatureValue.new(Object)]) }
33
-
34
- it "retains registered signatures that cannot accept any of the verified_signatures" do
35
- expect(registered_signature.accepts?(verified_signature)).to be_true
36
- expect(registered_signature_without_match.accepts?(verified_signature)).to be_false
37
-
38
- get_registered_signatures_service
39
- .should_receive(:execute)
40
- .and_return([registered_signature, registered_signature_without_match])
41
-
42
- get_verified_signatures_service
43
- .should_receive(:execute)
44
- .at_least(:once)
45
- .and_return([verified_signature])
46
-
47
- expect(subject.execute).to eq([registered_signature_without_match])
48
- end
49
- end
50
- end
51
-
52
-
@@ -1,63 +0,0 @@
1
- require 'unit_helper'
2
- require 'verified_double/get_verified_signatures'
3
-
4
- describe VerifiedDouble::GetVerifiedSignatures do
5
- let(:method_signature) { VerifiedDouble::MethodSignature.new }
6
-
7
- let(:nested_example_group){ double(:nested_example_group) }
8
-
9
- let(:parse_method_signature_service) {
10
- fire_double('VerifiedDouble::ParseMethodSignature') }
11
-
12
- let(:parse_method_signature_service_class) {
13
- fire_class_double('VerifiedDouble::ParseMethodSignature').as_replaced_constant }
14
-
15
- subject { described_class.new(nested_example_group) }
16
-
17
- describe "#execute" do
18
- let(:example_with_verified_contract_tag){
19
- double(:example_with_verified_contract_tag,
20
- metadata: { verifies_contract: 'signature' }) }
21
-
22
- let(:example_without_verified_contract_tag){
23
- double(:example_without_verified_contract_tag,
24
- metadata: { focus: true }) }
25
-
26
- it "filters rspec examples with the tag 'verifies_contract'" do
27
- nested_example_group
28
- .stub_chain(:class, :descendant_filtered_examples)
29
- .and_return([example_with_verified_contract_tag, example_without_verified_contract_tag])
30
-
31
- parse_method_signature_service_class
32
- .should_receive(:new)
33
- .with(example_with_verified_contract_tag.metadata[:verifies_contract])
34
- .and_return(parse_method_signature_service)
35
-
36
- parse_method_signature_service
37
- .should_receive(:execute)
38
- .and_return(method_signature)
39
-
40
- expect(subject.execute).to eq([method_signature])
41
- end
42
-
43
- it "returns unique signatures" do
44
- nested_example_group
45
- .stub_chain(:class, :descendant_filtered_examples)
46
- .and_return([example_with_verified_contract_tag, example_with_verified_contract_tag])
47
-
48
- parse_method_signature_service_class
49
- .should_receive(:new)
50
- .with(example_with_verified_contract_tag.metadata[:verifies_contract])
51
- .at_least(:once)
52
- .and_return(parse_method_signature_service)
53
-
54
- parse_method_signature_service
55
- .should_receive(:execute)
56
- .and_return(method_signature)
57
-
58
- expect(subject.execute).to eq([method_signature])
59
- end
60
- end
61
- end
62
-
63
-