Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit f0daad7

Browse files
Refactor field decorator specs to use shared example for match?
[#172379944](https://www.pivotaltracker.com/story/show/172379944)
1 parent aa31652 commit f0daad7

4 files changed

Lines changed: 8 additions & 92 deletions

spec/unit/decorators/field_service_instance_broker_decorator_spec.rb

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22
require 'decorators/field_service_instance_broker_decorator'
3+
require 'field_decorator_spec_shared_examples'
34

45
module VCAP::CloudController
56
RSpec.describe FieldServiceInstanceBrokerDecorator do
@@ -84,29 +85,7 @@ module VCAP::CloudController
8485
end
8586

8687
describe '.match?' do
87-
it 'matches hashes containing key symbol `service_plan.service_offering.service_broker` and value `name`' do
88-
expect(described_class.match?({ 'service_plan.service_offering.service_broker': ['name'], other: ['bar'] })).to be_truthy
89-
end
90-
91-
it 'matches hashes containing key symbol `service_plan.service_offering.service_broker` and value `guid`' do
92-
expect(described_class.match?({ 'service_plan.service_offering.service_broker': ['guid'], other: ['bar'] })).to be_truthy
93-
end
94-
95-
it 'matches hashes containing key symbol `service_plan.service_offering.service_broker` and value `name,guid`' do
96-
expect(described_class.match?({ 'service_plan.service_offering.service_broker': ['name', 'guid', 'something'], other: ['bar'] })).to be_truthy
97-
end
98-
99-
it 'does not match other values for a valid key' do
100-
expect(described_class.match?({ 'service_plan.service_offering.service_broker': ['foo'] })).to be_falsey
101-
end
102-
103-
it 'does not match other key values' do
104-
expect(described_class.match?({ other: ['bar'] })).to be_falsey
105-
end
106-
107-
it 'does not match non-hashes' do
108-
expect(described_class.match?('foo')).to be_falsey
109-
end
88+
it_behaves_like 'field decorator match?', 'service_plan.service_offering.service_broker', ['name', 'guid']
11089
end
11190
end
11291
end

spec/unit/decorators/field_service_instance_organization_decorator_spec.rb

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22
require 'decorators/field_service_instance_organization_decorator'
3+
require 'field_decorator_spec_shared_examples'
34

45
module VCAP::CloudController
56
RSpec.describe FieldServiceInstanceOrganizationDecorator do
@@ -70,29 +71,7 @@ module VCAP::CloudController
7071
end
7172

7273
describe '.match?' do
73-
it 'matches hashes containing key symbol `space.organization` and value `name`' do
74-
expect(described_class.match?({ 'space.organization': ['name'], other: ['bar'] })).to be_truthy
75-
end
76-
77-
it 'matches hashes containing key symbol `space.organization` and value `guid`' do
78-
expect(described_class.match?({ 'space.organization': ['guid'], other: ['bar'] })).to be_truthy
79-
end
80-
81-
it 'matches hashes containing key symbol `space.organization` and value `name,guid`' do
82-
expect(described_class.match?({ 'space.organization': ['name', 'guid', 'something'], other: ['bar'] })).to be_truthy
83-
end
84-
85-
it 'does not match other values for a valid key' do
86-
expect(described_class.match?({ 'space.organization': ['foo'] })).to be_falsey
87-
end
88-
89-
it 'does not match other key values' do
90-
expect(described_class.match?({ other: ['bar'] })).to be_falsey
91-
end
92-
93-
it 'does not match non-hashes' do
94-
expect(described_class.match?('foo')).to be_falsey
95-
end
74+
it_behaves_like 'field decorator match?', 'space.organization', ['name', 'guid']
9675
end
9776
end
9877
end

spec/unit/decorators/field_service_instance_plan_decorator_spec.rb

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22
require 'decorators/field_service_instance_plan_decorator'
3+
require 'field_decorator_spec_shared_examples'
34

45
module VCAP::CloudController
56
RSpec.describe FieldServiceInstancePlanDecorator do
@@ -92,33 +93,7 @@ module VCAP::CloudController
9293
end
9394

9495
describe '.match?' do
95-
it 'matches hashes containing key symbol `service_plan` and value `guid`' do
96-
expect(described_class.match?({ 'service_plan': ['guid'], other: ['bar'] })).to be_truthy
97-
end
98-
99-
it 'matches hashes containing key symbol `service_plan` and value `name`' do
100-
expect(described_class.match?({ 'service_plan': ['name'], other: ['bar'] })).to be_truthy
101-
end
102-
103-
it 'matches hashes containing key symbol `service_plan` and value `relationships.service_offering`' do
104-
expect(described_class.match?({ 'service_plan': ['relationships.service_offering'], other: ['bar'] })).to be_truthy
105-
end
106-
107-
it 'matches hashes containing key symbol `service_plan` and value `guid,relationships.service_offering`' do
108-
expect(described_class.match?({ 'service_plan': ['guid', 'relationships.service_offering', 'something'], other: ['bar'] })).to be_truthy
109-
end
110-
111-
it 'does not match other values for a valid key' do
112-
expect(described_class.match?({ 'service_plan': ['foo'] })).to be_falsey
113-
end
114-
115-
it 'does not match other key values' do
116-
expect(described_class.match?({ other: ['bar'] })).to be_falsey
117-
end
118-
119-
it 'does not match non-hashes' do
120-
expect(described_class.match?('foo')).to be_falsey
121-
end
96+
it_behaves_like 'field decorator match?', 'service_plan', ['name', 'guid', 'relationships.service_offering']
12297
end
12398
end
12499
end

spec/unit/decorators/field_service_instance_space_decorator_spec.rb

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22
require 'decorators/field_service_instance_space_decorator'
3+
require 'field_decorator_spec_shared_examples'
34

45
module VCAP::CloudController
56
RSpec.describe FieldServiceInstanceSpaceDecorator do
@@ -146,25 +147,7 @@ module VCAP::CloudController
146147
end
147148

148149
describe '.match?' do
149-
it 'matches hashes containing key symbol `space` and value `guid`' do
150-
expect(described_class.match?({ 'space': ['guid'], other: ['bar'] })).to be_truthy
151-
end
152-
153-
it 'matches hashes containing key symbol `space` and value `name`' do
154-
expect(described_class.match?({ 'space': ['name'], other: ['bar'] })).to be_truthy
155-
end
156-
157-
it 'matches hashes containing key symbol `space` and value `relationships.organization`' do
158-
expect(described_class.match?({ 'space': ['relationships.organization'], other: ['bar'] })).to be_truthy
159-
end
160-
161-
it 'does not match other values' do
162-
expect(described_class.match?({ other: ['bar'] })).to be_falsey
163-
end
164-
165-
it 'does not match non-hashes' do
166-
expect(described_class.match?('foo')).to be_falsey
167-
end
150+
it_behaves_like 'field decorator match?', 'space', ['name', 'guid', 'relationships.organization']
168151
end
169152
end
170153
end

0 commit comments

Comments
 (0)