diff options
Diffstat (limited to 'qa/spec/factory/base_spec.rb')
-rw-r--r-- | qa/spec/factory/base_spec.rb | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/qa/spec/factory/base_spec.rb b/qa/spec/factory/base_spec.rb index d7b92052894..e9584a27d63 100644 --- a/qa/spec/factory/base_spec.rb +++ b/qa/spec/factory/base_spec.rb @@ -4,8 +4,7 @@ describe QA::Factory::Base do include Support::StubENV let(:factory) { spy('factory') } - let(:product) { spy('product') } - let(:product_location) { 'http://product_location' } + let(:location) { 'http://location' } shared_context 'fabrication context' do subject do @@ -17,9 +16,8 @@ describe QA::Factory::Base do end before do - allow(subject).to receive(:current_url).and_return(product_location) + allow(subject).to receive(:current_url).and_return(location) allow(subject).to receive(:new).and_return(factory) - allow(QA::Factory::Product).to receive(:new).with(factory).and_return(product) end end @@ -28,7 +26,7 @@ describe QA::Factory::Base do it 'yields factory before calling factory method' do expect(factory).to receive(:something!).ordered - expect(factory).to receive(fabrication_method_used).ordered.and_return(product_location) + expect(factory).to receive(fabrication_method_used).ordered.and_return(location) subject.public_send(fabrication_method_called, factory: factory) do |factory| factory.something! @@ -37,7 +35,7 @@ describe QA::Factory::Base do it 'does not log the factory and build method when QA_DEBUG=false' do stub_env('QA_DEBUG', 'false') - expect(factory).to receive(fabrication_method_used).and_return(product_location) + expect(factory).to receive(fabrication_method_used).and_return(location) expect { subject.public_send(fabrication_method_called, 'something', factory: factory) } .not_to output.to_stdout @@ -71,17 +69,17 @@ describe QA::Factory::Base do it_behaves_like 'fabrication method', :fabricate_via_api! - it 'instantiates the factory, calls factory method returns fabrication product' do - expect(factory).to receive(:fabricate_via_api!).and_return(product_location) + it 'instantiates the factory, calls factory method returns the resource' do + expect(factory).to receive(:fabricate_via_api!).and_return(location) result = subject.fabricate_via_api!(factory: factory, parents: []) - expect(result).to eq(product) + expect(result).to eq(factory) end it 'logs the factory and build method when QA_DEBUG=true' do stub_env('QA_DEBUG', 'true') - expect(factory).to receive(:fabricate_via_api!).and_return(product_location) + expect(factory).to receive(:fabricate_via_api!).and_return(location) expect { subject.fabricate_via_api!(factory: factory, parents: []) } .to output(/==> Built a MyFactory via api with args \[\] in [\d\w\.\-]+/) @@ -100,10 +98,10 @@ describe QA::Factory::Base do expect(factory).to have_received(:fabricate!).with('something') end - it 'returns fabrication product' do + it 'returns fabrication resource' do result = subject.fabricate_via_browser_ui!('something', factory: factory, parents: []) - expect(result).to eq(product) + expect(result).to eq(factory) end it 'logs the factory and build method when QA_DEBUG=true' do @@ -140,44 +138,44 @@ describe QA::Factory::Base do describe '.attribute' do include_context 'simple factory' - it 'appends new product attribute' do + it 'appends new attribute' do expect(subject.attributes_names).to eq([:no_block, :test, :web_url]) end - context 'when the product attribute is populated via a block' do - it 'returns a fabrication product and defines factory attributes as its methods' do + context 'when the attribute is populated via a block' do + it 'returns value from the block' do result = subject.fabricate!(factory: factory) - expect(result).to be_a(QA::Factory::Product) + expect(result).to be_a(described_class) expect(result.test).to eq('block') end end - context 'when the product attribute is populated via the api' do + context 'when the attribute is populated via the api' do let(:api_resource) { { no_block: 'api' } } before do expect(factory).to receive(:api_resource).and_return(api_resource) end - it 'returns a fabrication product and defines factory attributes as its methods' do + it 'returns value from api' do result = subject.fabricate!(factory: factory) - expect(result).to be_a(QA::Factory::Product) + expect(result).to be_a(described_class) expect(result.no_block).to eq('api') end - context 'when the attribute also has a block in the factory' do + context 'when the attribute also has a block' do let(:api_resource) { { test: 'api_with_block' } } before do allow(QA::Runtime::Logger).to receive(:info) end - it 'returns the api value and emits an INFO log entry' do + it 'returns value from api and emits an INFO log entry' do result = subject.fabricate!(factory: factory) - expect(result).to be_a(QA::Factory::Product) + expect(result).to be_a(described_class) expect(result.test).to eq('api_with_block') expect(QA::Runtime::Logger) .to have_received(:info).with(/api_with_block/) @@ -185,15 +183,15 @@ describe QA::Factory::Base do end end - context 'when the product attribute is populated via a factory attribute' do + context 'when the attribute is populated via direct assignment' do before do factory.test = 'value' end - it 'returns a fabrication product and defines factory attributes as its methods' do + it 'returns value from the assignment' do result = subject.fabricate!(factory: factory) - expect(result).to be_a(QA::Factory::Product) + expect(result).to be_a(described_class) expect(result.test).to eq('value') end @@ -202,21 +200,21 @@ describe QA::Factory::Base do allow(factory).to receive(:api_resource).and_return({ test: 'api' }) end - it 'returns the factory attribute for the product' do + it 'returns value from the assignment' do result = subject.fabricate!(factory: factory) - expect(result).to be_a(QA::Factory::Product) + expect(result).to be_a(described_class) expect(result.test).to eq('value') end end end - context 'when the product attribute has no value' 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) expect { result.no_block } - .to raise_error(described_class::NoValueError, "No value was computed for product no_block of factory #{factory.class.name}.") + .to raise_error(described_class::NoValueError, "No value was computed for no_block of #{factory.class.name}.") end end end |