diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-11-02 12:32:28 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-11-05 17:20:57 +0300 |
commit | 4d0fd75cd5ceda72692a229d27ab6891fa8082e0 (patch) | |
tree | 7448b28ca974c9480e1e96b0d90c1322eeb9f0c7 /qa/spec | |
parent | c12a4a9ac7c04a215adf6062fec7bf31231c7d4a (diff) |
Rename QA::Factory to QA::Resource
* Factory::Base -> Resource::Base, and therefore:
* Factory::Resource::Project -> Resource::Project
Diffstat (limited to 'qa/spec')
-rw-r--r-- | qa/spec/factory/resource/user_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/resource/api_fabricator_spec.rb (renamed from qa/spec/factory/api_fabricator_spec.rb) | 46 | ||||
-rw-r--r-- | qa/spec/resource/base_spec.rb (renamed from qa/spec/factory/base_spec.rb) | 104 | ||||
-rw-r--r-- | qa/spec/resource/repository/push_spec.rb (renamed from qa/spec/factory/repository/push_spec.rb) | 2 |
4 files changed, 77 insertions, 77 deletions
diff --git a/qa/spec/factory/resource/user_spec.rb b/qa/spec/factory/resource/user_spec.rb index 2f6c59b3e69..820c506b715 100644 --- a/qa/spec/factory/resource/user_spec.rb +++ b/qa/spec/factory/resource/user_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe QA::Factory::Resource::User do +describe QA::Resource::User do describe "#fabricate_via_api!" do Response = Struct.new(:code, :body) diff --git a/qa/spec/factory/api_fabricator_spec.rb b/qa/spec/resource/api_fabricator_spec.rb index e5fbc064911..a5ed4422f6e 100644 --- a/qa/spec/factory/api_fabricator_spec.rb +++ b/qa/spec/resource/api_fabricator_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -describe QA::Factory::ApiFabricator do - let(:factory_without_api_support) do +describe QA::Resource::ApiFabricator do + let(:resource_without_api_support) do Class.new do def self.name - 'FooBarFactory' + 'FooBarResource' end end end - let(:factory_with_api_support) do + let(:resource_with_api_support) do Class.new do def self.name - 'FooBarFactory' + 'FooBarResource' end def api_get_path @@ -33,22 +33,22 @@ describe QA::Factory::ApiFabricator do allow(subject).to receive(:current_url).and_return('') end - subject { factory.tap { |f| f.include(described_class) }.new } + subject { resource.tap { |f| f.include(described_class) }.new } describe '#api_support?' do let(:api_client) { spy('Runtime::API::Client') } let(:api_client_instance) { double('API Client') } - context 'when factory does not support fabrication via the API' do - let(:factory) { factory_without_api_support } + context 'when resource does not support fabrication via the API' do + let(:resource) { resource_without_api_support } it 'returns false' do expect(subject).not_to be_api_support end end - context 'when factory supports fabrication via the API' do - let(:factory) { factory_with_api_support } + context 'when resource supports fabrication via the API' do + let(:resource) { resource_with_api_support } it 'returns false' do expect(subject).to be_api_support @@ -67,20 +67,20 @@ describe QA::Factory::ApiFabricator do allow(api_client_instance).to receive(:personal_access_token).and_return('foo') end - context 'when factory does not support fabrication via the API' do - let(:factory) { factory_without_api_support } + context 'when resource does not support fabrication via the API' do + let(:resource) { resource_without_api_support } it 'raises a NotImplementedError exception' do - expect { subject.fabricate_via_api! }.to raise_error(NotImplementedError, "Factory FooBarFactory does not support fabrication via the API!") + expect { subject.fabricate_via_api! }.to raise_error(NotImplementedError, "Resource FooBarResource does not support fabrication via the API!") end end - context 'when factory supports fabrication via the API' do - let(:factory) { factory_with_api_support } + context 'when resource supports fabrication via the API' do + let(:resource) { resource_with_api_support } let(:api_request) { spy('Runtime::API::Request') } let(:resource_web_url) { 'http://example.org/api/v4/foo' } - let(:resource) { { id: 1, name: 'John Doe', web_url: resource_web_url } } - let(:raw_post) { double('Raw POST response', code: 201, body: resource.to_json) } + let(:response) { { id: 1, name: 'John Doe', web_url: resource_web_url } } + let(:raw_post) { double('Raw POST response', code: 201, body: response.to_json) } before do stub_const('QA::Runtime::API::Request', api_request) @@ -103,7 +103,7 @@ describe QA::Factory::ApiFabricator do it 'populates api_resource with the resource' do subject.fabricate_via_api! - expect(subject.api_resource).to eq(resource) + expect(subject.api_resource).to eq(response) end context 'when the POST fails' do @@ -114,17 +114,17 @@ describe QA::Factory::ApiFabricator do expect(api_request).to receive(:new).with(api_client_instance, subject.api_post_path).and_return(double(url: resource_web_url)) expect(subject).to receive(:post).with(resource_web_url, subject.api_post_body).and_return(raw_post) - expect { subject.fabricate_via_api! }.to raise_error(described_class::ResourceFabricationFailedError, "Fabrication of FooBarFactory using the API failed (400) with `#{raw_post}`.") + expect { subject.fabricate_via_api! }.to raise_error(described_class::ResourceFabricationFailedError, "Fabrication of FooBarResource using the API failed (400) with `#{raw_post}`.") expect(subject.api_resource).to be_nil end end end context '#transform_api_resource' do - let(:factory) do + let(:resource) do Class.new do def self.name - 'FooBarFactory' + 'FooBarResource' end def api_get_path @@ -146,12 +146,12 @@ describe QA::Factory::ApiFabricator do end end - let(:resource) { { existing: 'foo', web_url: resource_web_url } } + let(:response) { { existing: 'foo', web_url: resource_web_url } } let(:transformed_resource) { { existing: 'foo', new: 'foobar', web_url: resource_web_url } } it 'transforms the resource' do expect(subject).to receive(:post).with(resource_web_url, subject.api_post_body).and_return(raw_post) - expect(subject).to receive(:transform_api_resource).with(resource).and_return(transformed_resource) + expect(subject).to receive(:transform_api_resource).with(response).and_return(transformed_resource) subject.fabricate_via_api! end diff --git a/qa/spec/factory/base_spec.rb b/qa/spec/resource/base_spec.rb index 990eba76460..dc9e16792d3 100644 --- a/qa/spec/factory/base_spec.rb +++ b/qa/spec/resource/base_spec.rb @@ -1,49 +1,49 @@ # frozen_string_literal: true -describe QA::Factory::Base do +describe QA::Resource::Base do include Support::StubENV - let(:factory) { spy('factory') } + let(:resource) { spy('resource') } let(:location) { 'http://location' } shared_context 'fabrication context' do subject do Class.new(described_class) do def self.name - 'MyFactory' + 'MyResource' end end end before do allow(subject).to receive(:current_url).and_return(location) - allow(subject).to receive(:new).and_return(factory) + allow(subject).to receive(:new).and_return(resource) end end shared_examples 'fabrication method' do |fabrication_method_called, actual_fabrication_method = nil| let(:fabrication_method_used) { actual_fabrication_method || fabrication_method_called } - it 'yields factory before calling factory method' do - expect(factory).to receive(:something!).ordered - expect(factory).to receive(fabrication_method_used).ordered.and_return(location) + it 'yields resource before calling resource method' do + expect(resource).to receive(:something!).ordered + expect(resource).to receive(fabrication_method_used).ordered.and_return(location) - subject.public_send(fabrication_method_called, factory: factory) do |factory| - factory.something! + subject.public_send(fabrication_method_called, resource: resource) do |resource| + resource.something! end end - it 'does not log the factory and build method when QA_DEBUG=false' do + it 'does not log the resource and build method when QA_DEBUG=false' do stub_env('QA_DEBUG', 'false') - expect(factory).to receive(fabrication_method_used).and_return(location) + expect(resource).to receive(fabrication_method_used).and_return(location) - expect { subject.public_send(fabrication_method_called, 'something', factory: factory) } + expect { subject.public_send(fabrication_method_called, 'something', resource: resource) } .not_to output.to_stdout end end describe '.fabricate!' do - context 'when factory does not support fabrication via the API' do + context 'when resource does not support fabrication via the API' do before do expect(described_class).to receive(:fabricate_via_api!).and_raise(NotImplementedError) end @@ -55,7 +55,7 @@ describe QA::Factory::Base do end end - context 'when factory supports fabrication via the API' do + context 'when resource supports fabrication via the API' do it 'calls .fabricate_via_browser_ui!' do expect(described_class).to receive(:fabricate_via_api!) @@ -69,20 +69,20 @@ describe QA::Factory::Base do it_behaves_like 'fabrication method', :fabricate_via_api! - it 'instantiates the factory, calls factory method returns the resource' do - expect(factory).to receive(:fabricate_via_api!).and_return(location) + it 'instantiates the resource, calls resource method returns the resource' do + expect(resource).to receive(:fabricate_via_api!).and_return(location) - result = subject.fabricate_via_api!(factory: factory, parents: []) + result = subject.fabricate_via_api!(resource: resource, parents: []) - expect(result).to eq(factory) + expect(result).to eq(resource) end - it 'logs the factory and build method when QA_DEBUG=true' do + it 'logs the resource and build method when QA_DEBUG=true' do stub_env('QA_DEBUG', 'true') - expect(factory).to receive(:fabricate_via_api!).and_return(location) + expect(resource).to receive(:fabricate_via_api!).and_return(location) - expect { subject.fabricate_via_api!('something', factory: factory, parents: []) } - .to output(/==> Built a MyFactory via api in [\d\.\-e]+ seconds+/) + expect { subject.fabricate_via_api!('something', resource: resource, parents: []) } + .to output(/==> Built a MyResource via api in [\d\.\-e]+ seconds+/) .to_stdout end end @@ -92,30 +92,30 @@ describe QA::Factory::Base do it_behaves_like 'fabrication method', :fabricate_via_browser_ui!, :fabricate! - it 'instantiates the factory and calls factory method' do - subject.fabricate_via_browser_ui!('something', factory: factory, parents: []) + it 'instantiates the resource and calls resource method' do + subject.fabricate_via_browser_ui!('something', resource: resource, parents: []) - expect(factory).to have_received(:fabricate!).with('something') + expect(resource).to have_received(:fabricate!).with('something') end it 'returns fabrication resource' do - result = subject.fabricate_via_browser_ui!('something', factory: factory, parents: []) + result = subject.fabricate_via_browser_ui!('something', resource: resource, parents: []) - expect(result).to eq(factory) + expect(result).to eq(resource) end - it 'logs the factory and build method when QA_DEBUG=true' do + it 'logs the resource and build method when QA_DEBUG=true' do stub_env('QA_DEBUG', 'true') - expect { subject.fabricate_via_browser_ui!('something', factory: factory, parents: []) } - .to output(/==> Built a MyFactory via browser_ui in [\d\.\-e]+ seconds+/) + expect { subject.fabricate_via_browser_ui!('something', resource: resource, parents: []) } + .to output(/==> Built a MyResource via browser_ui in [\d\.\-e]+ seconds+/) .to_stdout end end - shared_context 'simple factory' do + shared_context 'simple resource' do subject do - Class.new(QA::Factory::Base) do + Class.new(QA::Resource::Base) do attribute :test do 'block' end @@ -132,11 +132,11 @@ describe QA::Factory::Base do end end - let(:factory) { subject.new } + let(:resource) { subject.new } end describe '.attribute' do - include_context 'simple factory' + include_context 'simple resource' it 'appends new attribute' do expect(subject.attributes_names).to eq([:no_block, :test, :web_url]) @@ -144,7 +144,7 @@ describe QA::Factory::Base do context 'when the attribute is populated via a block' do it 'returns value from the block' do - result = subject.fabricate!(factory: factory) + result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) expect(result.test).to eq('block') @@ -155,11 +155,11 @@ describe QA::Factory::Base do let(:api_resource) { { no_block: 'api' } } before do - expect(factory).to receive(:api_resource).and_return(api_resource) + expect(resource).to receive(:api_resource).and_return(api_resource) end it 'returns value from api' do - result = subject.fabricate!(factory: factory) + result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) expect(result.no_block).to eq('api') @@ -173,7 +173,7 @@ describe QA::Factory::Base do end it 'returns value from api and emits an INFO log entry' do - result = subject.fabricate!(factory: factory) + result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) expect(result.test).to eq('api_with_block') @@ -185,11 +185,11 @@ describe QA::Factory::Base do context 'when the attribute is populated via direct assignment' do before do - factory.test = 'value' + resource.test = 'value' end it 'returns value from the assignment' do - result = subject.fabricate!(factory: factory) + result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) expect(result.test).to eq('value') @@ -197,11 +197,11 @@ describe QA::Factory::Base do context 'when the api also has such response' do before do - allow(factory).to receive(:api_resource).and_return({ test: 'api' }) + allow(resource).to receive(:api_resource).and_return({ test: 'api' }) end it 'returns value from the assignment' do - result = subject.fabricate!(factory: factory) + result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) expect(result.test).to eq('value') @@ -211,36 +211,36 @@ describe QA::Factory::Base do context 'when the attribute has no value' do it 'raises an error because no values could be found' do - result = subject.fabricate!(factory: factory) + result = subject.fabricate!(resource: resource) expect { result.no_block } - .to raise_error(described_class::NoValueError, "No value was computed for no_block of #{factory.class.name}.") + .to raise_error(described_class::NoValueError, "No value was computed for no_block of #{resource.class.name}.") end end end describe '#web_url' do - include_context 'simple factory' + include_context 'simple resource' it 'sets #web_url to #current_url after fabrication' do - subject.fabricate!(factory: factory) + subject.fabricate!(resource: resource) - expect(factory.web_url).to eq(subject.current_url) + expect(resource.web_url).to eq(subject.current_url) end end describe '#visit!' do - include_context 'simple factory' + include_context 'simple resource' before do - allow(factory).to receive(:visit) + allow(resource).to receive(:visit) end it 'calls #visit with the underlying #web_url' do - factory.web_url = subject.current_url - factory.visit! + resource.web_url = subject.current_url + resource.visit! - expect(factory).to have_received(:visit).with(subject.current_url) + expect(resource).to have_received(:visit).with(subject.current_url) end end end diff --git a/qa/spec/factory/repository/push_spec.rb b/qa/spec/resource/repository/push_spec.rb index 2eb6c008248..bf3ebce0cfe 100644 --- a/qa/spec/factory/repository/push_spec.rb +++ b/qa/spec/resource/repository/push_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe QA::Factory::Repository::Push do +describe QA::Resource::Repository::Push do describe '.files=' do let(:files) do [ |