diff options
Diffstat (limited to 'qa/spec/page')
-rw-r--r-- | qa/spec/page/base_spec.rb | 54 | ||||
-rw-r--r-- | qa/spec/page/element_spec.rb | 40 | ||||
-rw-r--r-- | qa/spec/page/logging_spec.rb | 62 | ||||
-rw-r--r-- | qa/spec/page/validator_spec.rb | 36 | ||||
-rw-r--r-- | qa/spec/page/view_spec.rb | 48 |
5 files changed, 120 insertions, 120 deletions
diff --git a/qa/spec/page/base_spec.rb b/qa/spec/page/base_spec.rb index 32a350f2154..d9b037a9599 100644 --- a/qa/spec/page/base_spec.rb +++ b/qa/spec/page/base_spec.rb @@ -1,88 +1,88 @@ describe QA::Page::Base do - describe 'page helpers' do - it 'exposes helpful page helpers' do + describe "page helpers" do + it "exposes helpful page helpers" do expect(subject).to respond_to :refresh, :wait, :scroll_to end end - describe '.view', 'DSL for defining view partials' do + describe ".view", "DSL for defining view partials" do subject do Class.new(described_class) do - view 'path/to/some/view.html.haml' do - element :something, 'string pattern' # rubocop:disable QA/ElementWithPattern + view "path/to/some/view.html.haml" do + element :something, "string pattern" # rubocop:disable QA/ElementWithPattern element :something_else, /regexp pattern/ # rubocop:disable QA/ElementWithPattern end - view 'path/to/some/_partial.html.haml' do - element :another_element, 'string pattern' # rubocop:disable QA/ElementWithPattern + view "path/to/some/_partial.html.haml" do + element :another_element, "string pattern" # rubocop:disable QA/ElementWithPattern end end end - it 'makes it possible to define page views' do + it "makes it possible to define page views" do expect(subject.views.size).to eq 2 - expect(subject.views).to all(be_an_instance_of QA::Page::View) + expect(subject.views).to all(be_an_instance_of(QA::Page::View)) end - it 'populates views objects with data about elements' do + it "populates views objects with data about elements" do expect(subject.elements.size).to eq 3 - expect(subject.elements).to all(be_an_instance_of QA::Page::Element) + expect(subject.elements).to all(be_an_instance_of(QA::Page::Element)) expect(subject.elements.map(&:name)) .to eq [:something, :something_else, :another_element] end end - describe '.errors' do - let(:view) { double('view') } + describe ".errors" do + let(:view) { double("view") } - context 'when page has views and elements defined' do + context "when page has views and elements defined" do before do allow(described_class).to receive(:views) .and_return([view]) - allow(view).to receive(:errors).and_return(['some error']) + allow(view).to receive(:errors).and_return(["some error"]) end - it 'iterates views composite and returns errors' do - expect(described_class.errors).to eq ['some error'] + it "iterates views composite and returns errors" do + expect(described_class.errors).to eq ["some error"] end end - context 'when page has no views and elements defined' do + context "when page has no views and elements defined" do before do allow(described_class).to receive(:views).and_return([]) end - it 'appends an error about missing views / elements block' do + it "appends an error about missing views / elements block" do expect(described_class.errors) - .to include 'Page class does not have views / elements defined!' + .to include "Page class does not have views / elements defined!" end end end - describe '#wait' do + describe "#wait" do subject { Class.new(described_class).new } - context 'when the condition is true' do - it 'does not refresh' do + context "when the condition is true" do + it "does not refresh" do expect(subject).not_to receive(:refresh) subject.wait(max: 0.01) { true } end - it 'returns true' do + it "returns true" do expect(subject.wait(max: 0.1) { true }).to be_truthy end end - context 'when the condition is false' do - it 'refreshes' do + context "when the condition is false" do + it "refreshes" do expect(subject).to receive(:refresh).at_least(:once) subject.wait(max: 0.01) { false } end - it 'returns false' do + it "returns false" do allow(subject).to receive(:refresh) expect(subject.wait(max: 0.01) { false }).to be_falsey diff --git a/qa/spec/page/element_spec.rb b/qa/spec/page/element_spec.rb index 8598c57ad34..5b485c27b3b 100644 --- a/qa/spec/page/element_spec.rb +++ b/qa/spec/page/element_spec.rb @@ -1,51 +1,51 @@ describe QA::Page::Element do - describe '#selector' do - it 'transforms element name into QA-specific selector' do + describe "#selector" do + it "transforms element name into QA-specific selector" do expect(described_class.new(:sign_in_button).selector) - .to eq 'qa-sign-in-button' + .to eq "qa-sign-in-button" end end - describe '#selector_css' do - it 'transforms element name into QA-specific clickable css selector' do + describe "#selector_css" do + it "transforms element name into QA-specific clickable css selector" do expect(described_class.new(:sign_in_button).selector_css) - .to eq '.qa-sign-in-button' + .to eq ".qa-sign-in-button" end end - context 'when pattern is an expression' do + context "when pattern is an expression" do subject { described_class.new(:something, /button 'Sign in'/) } - it 'matches when there is a match' do + it "matches when there is a match" do expect(subject.matches?("button 'Sign in'")).to be true end - it 'does not match if pattern is not present' do + it "does not match if pattern is not present" do expect(subject.matches?("button 'Sign out'")).to be false end end - context 'when pattern is a string' do - subject { described_class.new(:something, 'button') } + context "when pattern is a string" do + subject { described_class.new(:something, "button") } - it 'matches when there is match' do - expect(subject.matches?('some button in the view')).to be true + it "matches when there is match" do + expect(subject.matches?("some button in the view")).to be true end - it 'does not match if pattern is not present' do - expect(subject.matches?('text_field :name')).to be false + it "does not match if pattern is not present" do + expect(subject.matches?("text_field :name")).to be false end end - context 'when pattern is not provided' do + context "when pattern is not provided" do subject { described_class.new(:some_name) } - it 'matches when QA specific selector is present' do - expect(subject.matches?('some qa-some-name selector')).to be true + it "matches when QA specific selector is present" do + expect(subject.matches?("some qa-some-name selector")).to be true end - it 'does not match if QA selector is not there' do - expect(subject.matches?('some_name selector')).to be false + it "does not match if QA selector is not there" do + expect(subject.matches?("some_name selector")).to be false end end end diff --git a/qa/spec/page/logging_spec.rb b/qa/spec/page/logging_spec.rb index 707a7ff6d98..451dd5f0713 100644 --- a/qa/spec/page/logging_spec.rb +++ b/qa/spec/page/logging_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'capybara/dsl' -require 'logger' +require "capybara/dsl" +require "logger" describe QA::Support::Page::Logging do let(:page) { double.as_null_object } @@ -12,22 +12,22 @@ describe QA::Support::Page::Logging do QA::Runtime::Logger.logger = logger allow(Capybara).to receive(:current_session).and_return(page) - allow(page).to receive(:current_url).and_return('http://current-url') + allow(page).to receive(:current_url).and_return("http://current-url") allow(page).to receive(:has_css?).with(any_args).and_return(true) end subject do - Class.new(QA::Page::Base) do + Class.new(QA::Page::Base) { prepend QA::Support::Page::Logging - end.new + }.new end - it 'logs refresh' do + it "logs refresh" do expect { subject.refresh } .to output(%r{refreshing http://current-url}).to_stdout_from_any_process end - it 'logs wait' do + it "logs wait" do expect { subject.wait(max: 0) {} } .to output(/next wait uses reload: true/).to_stdout_from_any_process expect { subject.wait(max: 0) {} } @@ -36,7 +36,7 @@ describe QA::Support::Page::Logging do .to output(/ended wait after .* seconds$/).to_stdout_from_any_process end - it 'logs wait with reload false' do + it "logs wait with reload false" do expect { subject.wait(max: 0, reload: false) {} } .to output(/next wait uses reload: false/).to_stdout_from_any_process expect { subject.wait(max: 0, reload: false) {} } @@ -45,87 +45,87 @@ describe QA::Support::Page::Logging do .to output(/ended wait after .* seconds$/).to_stdout_from_any_process end - it 'logs scroll_to' do + it "logs scroll_to" do expect { subject.scroll_to(:element) } .to output(/scrolling to :element/).to_stdout_from_any_process end - it 'logs asset_exists?' do - expect { subject.asset_exists?('http://asset-url') } + it "logs asset_exists?" do + expect { subject.asset_exists?("http://asset-url") } .to output(%r{asset_exists\? http://asset-url returned false}).to_stdout_from_any_process end - it 'logs find_element' do + it "logs find_element" do expect { subject.find_element(:element) } .to output(/finding :element/).to_stdout_from_any_process expect { subject.find_element(:element) } .to output(/found :element/).to_stdout_from_any_process end - it 'logs find_element with text' do - expect { subject.find_element(:element, text: 'foo') } + it "logs find_element with text" do + expect { subject.find_element(:element, text: "foo") } .to output(/finding :element with text "foo"/).to_stdout_from_any_process - expect { subject.find_element(:element, text: 'foo') } + expect { subject.find_element(:element, text: "foo") } .to output(/found :element/).to_stdout_from_any_process end - it 'logs click_element' do + it "logs click_element" do expect { subject.click_element(:element) } .to output(/clicking :element/).to_stdout_from_any_process end - it 'logs fill_element' do - expect { subject.fill_element(:element, 'foo') } + it "logs fill_element" do + expect { subject.fill_element(:element, "foo") } .to output(/filling :element with "foo"/).to_stdout_from_any_process end - it 'logs has_element?' do + it "logs has_element?" do expect { subject.has_element?(:element) } .to output(/has_element\? :element \(wait: 2\) returned: true/).to_stdout_from_any_process end - it 'logs has_element? with text' do + it "logs has_element? with text" do expect { subject.has_element?(:element, text: "some text") } .to output(/has_element\? :element with text \"some text\" \(wait: 2\) returned: true/).to_stdout_from_any_process end - it 'logs has_no_element?' do + it "logs has_no_element?" do allow(page).to receive(:has_no_css?).and_return(true) expect { subject.has_no_element?(:element) } .to output(/has_no_element\? :element returned true/).to_stdout_from_any_process end - it 'logs has_text?' do + it "logs has_text?" do allow(page).to receive(:has_text?).and_return(true) - expect { subject.has_text? 'foo' } + expect { subject.has_text? "foo" } .to output(/has_text\?\('foo'\) returned true/).to_stdout_from_any_process end - it 'logs has_no_text?' do - allow(page).to receive(:has_no_text?).with('foo').and_return(true) + it "logs has_no_text?" do + allow(page).to receive(:has_no_text?).with("foo").and_return(true) - expect { subject.has_no_text? 'foo' } + expect { subject.has_no_text? "foo" } .to output(/has_no_text\?\('foo'\) returned true/).to_stdout_from_any_process end - it 'logs finished_loading?' do + it "logs finished_loading?" do expect { subject.finished_loading? } .to output(/waiting for loading to complete\.\.\./).to_stdout_from_any_process expect { subject.finished_loading? } .to output(/loading complete after .* seconds$/).to_stdout_from_any_process end - it 'logs within_element' do + it "logs within_element" do expect { subject.within_element(:element) } .to output(/within element :element/).to_stdout_from_any_process expect { subject.within_element(:element) } .to output(/end within element :element/).to_stdout_from_any_process end - context 'all_elements' do - it 'logs the number of elements found' do + context "all_elements" do + it "logs the number of elements found" do allow(page).to receive(:all).and_return([1, 2]) expect { subject.all_elements(:element) } @@ -134,7 +134,7 @@ describe QA::Support::Page::Logging do .to output(/found 2 :element/).to_stdout_from_any_process end - it 'logs 0 if no elements are found' do + it "logs 0 if no elements are found" do allow(page).to receive(:all).and_return([]) expect { subject.all_elements(:element) } diff --git a/qa/spec/page/validator_spec.rb b/qa/spec/page/validator_spec.rb index 0ae6e66d767..7c243fd638b 100644 --- a/qa/spec/page/validator_spec.rb +++ b/qa/spec/page/validator_spec.rb @@ -1,33 +1,33 @@ describe QA::Page::Validator do - describe '#constants' do + describe "#constants" do subject do described_class.new(QA::Page::Project) end - it 'returns all constants that are module children' do + it "returns all constants that are module children" do expect(subject.constants) .to include QA::Page::Project::New, QA::Page::Project::Settings end end - describe '#descendants' do + describe "#descendants" do subject do described_class.new(QA::Page::Project) end - it 'recursively returns all descendants that are page objects' do + it "recursively returns all descendants that are page objects" do expect(subject.descendants) .to include QA::Page::Project::New, QA::Page::Project::Settings::Repository end - it 'does not return modules that aggregate page objects' do + it "does not return modules that aggregate page objects" do expect(subject.descendants) .not_to include QA::Page::Project::Settings end end - context 'when checking validation errors' do - let(:view) { spy('view') } + context "when checking validation errors" do + let(:view) { spy("view") } before do allow(QA::Page::Admin::Settings::Repository) @@ -38,38 +38,38 @@ describe QA::Page::Validator do described_class.new(QA::Page::Admin) end - context 'when there are no validation errors' do + context "when there are no validation errors" do before do allow(view).to receive(:errors).and_return([]) end - describe '#errors' do - it 'does not return errors' do + describe "#errors" do + it "does not return errors" do expect(subject.errors).to be_empty end end - describe '#validate!' do - it 'does not raise error' do + describe "#validate!" do + it "does not raise error" do expect { subject.validate! }.not_to raise_error end end end - context 'when there are validation errors' do + context "when there are validation errors" do before do allow(view).to receive(:errors) - .and_return(['some error', 'another error']) + .and_return(["some error", "another error"]) end - describe '#errors' do - it 'returns errors' do + describe "#errors" do + it "returns errors" do expect(subject.errors.count).to eq 2 end end - describe '#validate!' do - it 'raises validation error' do + describe "#validate!" do + it "raises validation error" do expect { subject.validate! } .to raise_error described_class::ValidationError end diff --git a/qa/spec/page/view_spec.rb b/qa/spec/page/view_spec.rb index d7b3ccd316d..ac33de53a42 100644 --- a/qa/spec/page/view_spec.rb +++ b/qa/spec/page/view_spec.rb @@ -1,69 +1,69 @@ describe QA::Page::View do let(:element) do - double('element', name: :something, pattern: /some element/) + double("element", name: :something, pattern: /some element/) end - subject { described_class.new('some/file.html', [element]) } + subject { described_class.new("some/file.html", [element]) } - describe '.evaluate' do - it 'evaluates a block and returns a DSL object' do - results = described_class.evaluate do + describe ".evaluate" do + it "evaluates a block and returns a DSL object" do + results = described_class.evaluate { element :something element :something_else - end + } expect(results.elements.size).to eq 2 end end - describe '#pathname' do - it 'returns an absolute and clean path to the view' do - expect(subject.pathname.to_s).not_to include 'qa/page/' - expect(subject.pathname.to_s).to include 'some/file.html' + describe "#pathname" do + it "returns an absolute and clean path to the view" do + expect(subject.pathname.to_s).not_to include "qa/page/" + expect(subject.pathname.to_s).to include "some/file.html" end end - describe '#errors' do - context 'when view partial is present' do + describe "#errors" do + context "when view partial is present" do before do allow(subject.pathname).to receive(:readable?) .and_return(true) end - context 'when pattern is found' do + context "when pattern is found" do before do allow(::File).to receive(:foreach) - .and_yield('some element').once + .and_yield("some element").once allow(element).to receive(:matches?) - .with('some element').and_return(true) + .with("some element").and_return(true) end - it 'walks through the view and asserts on elements existence' do + it "walks through the view and asserts on elements existence" do expect(subject.errors).to be_empty end end - context 'when pattern has not been found' do + context "when pattern has not been found" do before do allow(::File).to receive(:foreach) - .and_yield('some element').once + .and_yield("some element").once allow(element).to receive(:matches?) - .with('some element').and_return(false) + .with("some element").and_return(false) end - it 'returns an array of errors related to missing elements' do + it "returns an array of errors related to missing elements" do expect(subject.errors).not_to be_empty expect(subject.errors.first) - .to match %r(Missing element `.*` in `.*/some/file.html` view) + .to match %r{Missing element `.*` in `.*/some/file.html` view} end end end - context 'when view partial has not been found' do - it 'returns an error when it is not able to find the partial' do + context "when view partial has not been found" do + it "returns an error when it is not able to find the partial" do expect(subject.errors).to be_one expect(subject.errors.first) - .to match %r(Missing view partial `.*/some/file.html`!) + .to match %r{Missing view partial `.*/some/file.html`!} end end end |