diff options
Diffstat (limited to 'qa/spec/resource/base_spec.rb')
-rw-r--r-- | qa/spec/resource/base_spec.rb | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/qa/spec/resource/base_spec.rb b/qa/spec/resource/base_spec.rb index 4a6b76c869f..2b72b90f499 100644 --- a/qa/spec/resource/base_spec.rb +++ b/qa/spec/resource/base_spec.rb @@ -3,14 +3,14 @@ describe QA::Resource::Base do include Helpers::StubENV - let(:resource) { spy('resource') } - let(:location) { 'http://location' } + let(:resource) { spy("resource") } + let(:location) { "http://location" } - shared_context 'fabrication context' do + shared_context "fabrication context" do subject do Class.new(described_class) do def self.name - 'MyResource' + "MyResource" end end end @@ -21,10 +21,10 @@ describe QA::Resource::Base do end end - shared_examples 'fabrication method' do |fabrication_method_called, actual_fabrication_method = nil| + shared_examples "fabrication method" do |fabrication_method_called, actual_fabrication_method = nil| let(:fabrication_method_used) { actual_fabrication_method || fabrication_method_called } - it 'yields resource before calling resource method' do + 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) @@ -33,30 +33,30 @@ describe QA::Resource::Base do end end - it 'does not log the resource and build method when QA_DEBUG=false' do - stub_env('QA_DEBUG', 'false') + it "does not log the resource and build method when QA_DEBUG=false" do + stub_env("QA_DEBUG", "false") expect(resource).to receive(fabrication_method_used).and_return(location) - expect { subject.public_send(fabrication_method_called, 'something', resource: resource) } + expect { subject.public_send(fabrication_method_called, "something", resource: resource) } .not_to output.to_stdout end end - describe '.fabricate!' do - context 'when resource does not support fabrication via the API' do + describe ".fabricate!" 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 - it 'calls .fabricate_via_browser_ui!' do + it "calls .fabricate_via_browser_ui!" do expect(described_class).to receive(:fabricate_via_browser_ui!) described_class.fabricate! end end - context 'when resource supports fabrication via the API' do - it 'calls .fabricate_via_browser_ui!' 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!) described_class.fabricate! @@ -64,12 +64,12 @@ describe QA::Resource::Base do end end - describe '.fabricate_via_api!' do - include_context 'fabrication context' + describe ".fabricate_via_api!" do + include_context "fabrication context" - it_behaves_like 'fabrication method', :fabricate_via_api! + it_behaves_like "fabrication method", :fabricate_via_api! - it 'instantiates the resource, calls resource method returns the resource' do + 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!(resource: resource, parents: []) @@ -77,57 +77,57 @@ describe QA::Resource::Base do expect(result).to eq(resource) end - it 'logs the resource and build method when QA_DEBUG=true' do - stub_env('QA_DEBUG', 'true') + it "logs the resource and build method when QA_DEBUG=true" do + stub_env("QA_DEBUG", "true") expect(resource).to receive(:fabricate_via_api!).and_return(location) - expect { subject.fabricate_via_api!('something', resource: resource, parents: []) } + expect { subject.fabricate_via_api!("something", resource: resource, parents: []) } .to output(/==> Built a MyResource via api in [\d\.\-e]+ seconds+/) .to_stdout end end - describe '.fabricate_via_browser_ui!' do - include_context 'fabrication context' + describe ".fabricate_via_browser_ui!" do + include_context "fabrication context" - it_behaves_like 'fabrication method', :fabricate_via_browser_ui!, :fabricate! + it_behaves_like "fabrication method", :fabricate_via_browser_ui!, :fabricate! - it 'instantiates the resource and calls resource method' do - subject.fabricate_via_browser_ui!('something', resource: resource, parents: []) + it "instantiates the resource and calls resource method" do + subject.fabricate_via_browser_ui!("something", resource: resource, parents: []) - expect(resource).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', resource: resource, parents: []) + it "returns fabrication resource" do + result = subject.fabricate_via_browser_ui!("something", resource: resource, parents: []) expect(result).to eq(resource) end - it 'logs the resource and build method when QA_DEBUG=true' do - stub_env('QA_DEBUG', 'true') + it "logs the resource and build method when QA_DEBUG=true" do + stub_env("QA_DEBUG", "true") - expect { subject.fabricate_via_browser_ui!('something', resource: resource, parents: []) } + 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 resource' do + shared_context "simple resource" do subject do Class.new(QA::Resource::Base) do attribute :test do - 'block' + "block" end attribute :no_block def fabricate! - 'any' + "any" end def self.current_url - 'http://stub' + "http://stub" end end end @@ -135,78 +135,78 @@ describe QA::Resource::Base do let(:resource) { subject.new } end - describe '.attribute' do - include_context 'simple resource' + describe ".attribute" do + include_context "simple resource" - context 'when the attribute is populated via a block' do - it 'returns value from the block' do + context "when the attribute is populated via a block" do + it "returns value from the block" do result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) - expect(result.test).to eq('block') + expect(result.test).to eq("block") end end - context 'when the attribute is populated via the api' do - let(:api_resource) { { no_block: 'api' } } + context "when the attribute is populated via the api" do + let(:api_resource) { {no_block: "api"} } before do expect(resource).to receive(:api_resource).and_return(api_resource) end - it 'returns value from api' do + it "returns value from api" do result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) - expect(result.no_block).to eq('api') + expect(result.no_block).to eq("api") end - context 'when the attribute also has a block' do - let(:api_resource) { { test: 'api_with_block' } } + 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 value from api and emits an INFO log entry' do + it "returns value from api and emits an INFO log entry" do result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) - expect(result.test).to eq('api_with_block') + expect(result.test).to eq("api_with_block") expect(QA::Runtime::Logger) .to have_received(:info).with(/api_with_block/) end end end - context 'when the attribute is populated via direct assignment' do + context "when the attribute is populated via direct assignment" do before do - resource.test = 'value' + resource.test = "value" end - it 'returns value from the assignment' do + it "returns value from the assignment" do result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) - expect(result.test).to eq('value') + expect(result.test).to eq("value") end - context 'when the api also has such response' do + context "when the api also has such response" do before do - allow(resource).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 + it "returns value from the assignment" do result = subject.fabricate!(resource: resource) expect(result).to be_a(described_class) - expect(result.test).to eq('value') + expect(result.test).to eq("value") end end end - context 'when the attribute has no value' do - it 'raises an error because no values could be found' do + context "when the attribute has no value" do + it "raises an error because no values could be found" do result = subject.fabricate!(resource: resource) expect { result.no_block } @@ -214,61 +214,61 @@ describe QA::Resource::Base do end end - context 'when multiple resources have the same attribute name' do + context "when multiple resources have the same attribute name" do let(:base) do Class.new(QA::Resource::Base) do def fabricate! - 'any' + "any" end def self.current_url - 'http://stub' + "http://stub" end end end let(:first_resource) do Class.new(base) do attribute :test do - 'first block' + "first block" end end end let(:second_resource) do Class.new(base) do attribute :test do - 'second block' + "second block" end end end - it 'has unique attribute values' do + it "has unique attribute values" do first_result = first_resource.fabricate!(resource: first_resource.new) second_result = second_resource.fabricate!(resource: second_resource.new) - expect(first_result.test).to eq 'first block' - expect(second_result.test).to eq 'second block' + expect(first_result.test).to eq "first block" + expect(second_result.test).to eq "second block" end end end - describe '#web_url' do - include_context 'simple resource' + describe "#web_url" do + include_context "simple resource" - it 'sets #web_url to #current_url after fabrication' do + it "sets #web_url to #current_url after fabrication" do subject.fabricate!(resource: resource) expect(resource.web_url).to eq(subject.current_url) end end - describe '#visit!' do - include_context 'simple resource' + describe "#visit!" do + include_context "simple resource" before do allow(resource).to receive(:visit) end - it 'calls #visit with the underlying #web_url' do + it "calls #visit with the underlying #web_url" do resource.web_url = subject.current_url resource.visit! |