diff options
author | Constance Okoghenun <cokoghenun@gitlab.com> | 2018-01-09 00:50:54 +0100 |
---|---|---|
committer | Constance Okoghenun <cokoghenun@gitlab.com> | 2018-01-09 00:50:54 +0100 |
commit | 85e8acedaf1d4e51335c59a0efa2f95576a4fde3 (patch) | |
tree | 9b21d76626568158cf746e2a7eb4853efe3aa0d5 /qa | |
parent | cdcade0dd4e748bcf0119b307c06993e0669f507 (diff) | |
parent | bd50ecbad8c00e7c9ab5c60fa8bc839a8905b4ab (diff) | |
download | gitlab-ce-move-project-dropdown.tar.gz |
Resolved conflictsmove-project-dropdown
Diffstat (limited to 'qa')
30 files changed, 627 insertions, 71 deletions
diff --git a/qa/README.md b/qa/README.md index 1cfbbdd9d42..7f2dd39ff63 100644 --- a/qa/README.md +++ b/qa/README.md @@ -33,7 +33,14 @@ You can also supply specific tests to run as another parameter. For example, to test the EE license specs, you can run: ``` -EE_LICENSE="<YOUR LICENSE KEY>" bin/qa Test::Instance http://localhost qa/ee +EE_LICENSE="<YOUR LICENSE KEY>" bin/qa Test::Instance http://localhost qa/specs/features/ee +``` + +Since the arguments would be passed to `rspec`, you could use all `rspec` +options there. For example, passing `--backtrace` and also line number: + +``` +bin/qa Test::Instance http://localhost qa/specs/features/login/standard_spec.rb:3 --backtrace ``` ### Overriding the authenticated user @@ -10,6 +10,7 @@ module QA autoload :Namespace, 'qa/runtime/namespace' autoload :Scenario, 'qa/runtime/scenario' autoload :Browser, 'qa/runtime/browser' + autoload :Env, 'qa/runtime/env' end ## @@ -17,11 +18,14 @@ module QA # module Factory autoload :Base, 'qa/factory/base' + autoload :Dependency, 'qa/factory/dependency' + autoload :Product, 'qa/factory/product' module Resource autoload :Sandbox, 'qa/factory/resource/sandbox' autoload :Group, 'qa/factory/resource/group' autoload :Project, 'qa/factory/resource/project' + autoload :DeployKey, 'qa/factory/resource/deploy_key' end module Repository @@ -67,10 +71,15 @@ module QA module Main autoload :Login, 'qa/page/main/login' - autoload :Menu, 'qa/page/main/menu' autoload :OAuth, 'qa/page/main/oauth' end + module Menu + autoload :Main, 'qa/page/menu/main' + autoload :Side, 'qa/page/menu/side' + autoload :Admin, 'qa/page/menu/admin' + end + module Dashboard autoload :Projects, 'qa/page/dashboard/projects' autoload :Groups, 'qa/page/dashboard/groups' @@ -84,10 +93,15 @@ module QA module Project autoload :New, 'qa/page/project/new' autoload :Show, 'qa/page/project/show' + + module Settings + autoload :Common, 'qa/page/project/settings/common' + autoload :Repository, 'qa/page/project/settings/repository' + autoload :DeployKeys, 'qa/page/project/settings/deploy_keys' + end end module Admin - autoload :Menu, 'qa/page/admin/menu' autoload :Settings, 'qa/page/admin/settings' end diff --git a/qa/qa/factory/base.rb b/qa/qa/factory/base.rb index 7b951a99b69..00851a7bece 100644 --- a/qa/qa/factory/base.rb +++ b/qa/qa/factory/base.rb @@ -1,15 +1,34 @@ module QA module Factory class Base + def fabricate!(*_args) + raise NotImplementedError + end + def self.fabricate!(*args) - new.tap do |factory| + Factory::Product.populate!(new) do |factory| yield factory if block_given? - return factory.fabricate!(*args) + + dependencies.each do |name, signature| + Factory::Dependency.new(name, factory, signature).build! + end + + factory.fabricate!(*args) end end - def fabricate!(*_args) - raise NotImplementedError + def self.dependencies + @dependencies ||= {} + end + + def self.dependency(factory, as:, &block) + as.tap do |name| + class_eval { attr_accessor name } + + Dependency::Signature.new(factory, block).tap do |signature| + dependencies.store(name, signature) + end + end end end end diff --git a/qa/qa/factory/dependency.rb b/qa/qa/factory/dependency.rb new file mode 100644 index 00000000000..d0e85a68237 --- /dev/null +++ b/qa/qa/factory/dependency.rb @@ -0,0 +1,38 @@ +module QA + module Factory + class Dependency + Signature = Struct.new(:factory, :block) + + def initialize(name, factory, signature) + @name = name + @factory = factory + @signature = signature + end + + def overridden? + !!@factory.public_send(@name) + end + + def build! + return if overridden? + + Builder.new(@signature).fabricate!.tap do |product| + @factory.public_send("#{@name}=", product) + end + end + + class Builder + def initialize(signature) + @factory = signature.factory + @block = signature.block + end + + def fabricate! + @factory.fabricate! do |factory| + @block&.call(factory) + end + end + end + end + end +end diff --git a/qa/qa/factory/product.rb b/qa/qa/factory/product.rb new file mode 100644 index 00000000000..df35bbbb443 --- /dev/null +++ b/qa/qa/factory/product.rb @@ -0,0 +1,26 @@ +require 'capybara/dsl' + +module QA + module Factory + class Product + include Capybara::DSL + + def initialize(factory) + @factory = factory + @location = current_url + end + + def visit! + visit @location + end + + def self.populate!(factory) + raise ArgumentError unless block_given? + + yield factory + + new(factory) + end + end + end +end diff --git a/qa/qa/factory/repository/push.rb b/qa/qa/factory/repository/push.rb index 1d5375d8c76..2f4de4173d4 100644 --- a/qa/qa/factory/repository/push.rb +++ b/qa/qa/factory/repository/push.rb @@ -1,16 +1,13 @@ -require "pry-byebug" - module QA module Factory module Repository class Push < Factory::Base - PAGE_REGEX_CHECK = - %r{\/#{Runtime::Namespace.sandbox_name}\/qa-test[^\/]+\/{1}[^\/]+\z}.freeze + attr_writer :file_name, :file_content, :commit_message, :branch_name - attr_writer :file_name, - :file_content, - :commit_message, - :branch_name + dependency Factory::Resource::Project, as: :project do |project| + project.name = 'project-with-code' + project.description = 'Project with repository' + end def initialize @file_name = 'file.txt' @@ -20,12 +17,10 @@ module QA end def fabricate! + project.visit! + Git::Repository.perform do |repository| repository.location = Page::Project::Show.act do - unless PAGE_REGEX_CHECK.match(current_path) - raise "To perform this scenario the current page should be project show." - end - choose_repository_clone_http repository_location end diff --git a/qa/qa/factory/resource/deploy_key.rb b/qa/qa/factory/resource/deploy_key.rb new file mode 100644 index 00000000000..7c58e70bcc4 --- /dev/null +++ b/qa/qa/factory/resource/deploy_key.rb @@ -0,0 +1,31 @@ +module QA + module Factory + module Resource + class DeployKey < Factory::Base + attr_accessor :title, :key + + dependency Factory::Resource::Project, as: :project do |project| + project.name = 'project-to-deploy' + project.description = 'project for adding deploy key test' + end + + def fabricate! + project.visit! + + Page::Menu::Side.act do + click_repository_setting + end + + Page::Project::Settings::Repository.perform do |setting| + setting.expand_deploy_keys do |page| + page.fill_key_title(title) + page.fill_key_value(key) + + page.add_key + end + end + end + end + end + end +end diff --git a/qa/qa/factory/resource/group.rb b/qa/qa/factory/resource/group.rb index a081cd94d39..9f13e26f35c 100644 --- a/qa/qa/factory/resource/group.rb +++ b/qa/qa/factory/resource/group.rb @@ -4,17 +4,29 @@ module QA class Group < Factory::Base attr_writer :path, :description + dependency Factory::Resource::Sandbox, as: :sandbox + def initialize @path = Runtime::Namespace.name @description = "QA test run at #{Runtime::Namespace.time}" end def fabricate! - Page::Group::New.perform do |group| - group.set_path(@path) - group.set_description(@description) - group.set_visibility('Private') - group.create + sandbox.visit! + + Page::Group::Show.perform do |page| + if page.has_subgroup?(@path) + page.go_to_subgroup(@path) + else + page.go_to_new_subgroup + + Page::Group::New.perform do |group| + group.set_path(@path) + group.set_description(@description) + group.set_visibility('Private') + group.create + end + end end end end diff --git a/qa/qa/factory/resource/project.rb b/qa/qa/factory/resource/project.rb index 64fcfb084bb..07c2e3086d1 100644 --- a/qa/qa/factory/resource/project.rb +++ b/qa/qa/factory/resource/project.rb @@ -6,26 +6,17 @@ module QA class Project < Factory::Base attr_writer :description + dependency Factory::Resource::Group, as: :group + def name=(name) @name = "#{name}-#{SecureRandom.hex(8)}" + @description = 'My awesome project' end def fabricate! - Factory::Resource::Sandbox.fabricate! - - Page::Group::Show.perform do |page| - if page.has_subgroup?(Runtime::Namespace.name) - page.go_to_subgroup(Runtime::Namespace.name) - else - page.go_to_new_subgroup + group.visit! - Factory::Resource::Group.fabricate! do |group| - group.path = Runtime::Namespace.name - end - end - - page.go_to_new_project - end + Page::Group::Show.act { go_to_new_project } Page::Project::New.perform do |page| page.choose_test_namespace diff --git a/qa/qa/factory/resource/sandbox.rb b/qa/qa/factory/resource/sandbox.rb index fd2177915c5..ad376988e82 100644 --- a/qa/qa/factory/resource/sandbox.rb +++ b/qa/qa/factory/resource/sandbox.rb @@ -6,18 +6,24 @@ module QA # creating it if it doesn't yet exist. # class Sandbox < Factory::Base + def initialize + @name = Runtime::Namespace.sandbox_name + end + def fabricate! - Page::Main::Menu.act { go_to_groups } + Page::Menu::Main.act { go_to_groups } Page::Dashboard::Groups.perform do |page| - if page.has_group?(Runtime::Namespace.sandbox_name) - page.go_to_group(Runtime::Namespace.sandbox_name) + if page.has_group?(@name) + page.go_to_group(@name) else page.go_to_new_group - Resource::Group.fabricate! do |group| - group.path = Runtime::Namespace.sandbox_name - group.description = 'GitLab QA Sandbox' + Page::Group::New.perform do |group| + group.set_path(@name) + group.set_description('GitLab QA Sandbox') + group.set_visibility('Private') + group.create end end end diff --git a/qa/qa/factory/settings/hashed_storage.rb b/qa/qa/factory/settings/hashed_storage.rb index eb3b28f2613..13ce2435fe4 100644 --- a/qa/qa/factory/settings/hashed_storage.rb +++ b/qa/qa/factory/settings/hashed_storage.rb @@ -6,15 +6,15 @@ module QA raise ArgumentError unless traits.include?(:enabled) Page::Main::Login.act { sign_in_using_credentials } - Page::Main::Menu.act { go_to_admin_area } - Page::Admin::Menu.act { go_to_settings } + Page::Menu::Main.act { go_to_admin_area } + Page::Menu::Admin.act { go_to_settings } Page::Admin::Settings.act do enable_hashed_storage save_settings end - QA::Page::Main::Menu.act { sign_out } + QA::Page::Menu::Main.act { sign_out } end end end diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 59cd147e055..8f999511d58 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -23,7 +23,7 @@ module QA def password=(pass) @password = pass - @uri.password = CGI.escape(pass) + @uri.password = CGI.escape(pass).gsub('+', '%20') end def use_default_credentials diff --git a/qa/qa/page/group/show.rb b/qa/qa/page/group/show.rb index 100e71ae157..0a16c07d64b 100644 --- a/qa/qa/page/group/show.rb +++ b/qa/qa/page/group/show.rb @@ -21,6 +21,7 @@ module QA find('.dropdown-toggle').click find("li[data-value='new-subgroup']").click end + find("input[data-action='new-subgroup']").click end @@ -29,6 +30,7 @@ module QA find('.dropdown-toggle').click find("li[data-value='new-project']").click end + find("input[data-action='new-project']").click end end diff --git a/qa/qa/page/admin/menu.rb b/qa/qa/page/menu/admin.rb index dd289ffe269..07fe40fda3a 100644 --- a/qa/qa/page/admin/menu.rb +++ b/qa/qa/page/menu/admin.rb @@ -1,7 +1,7 @@ module QA module Page - module Admin - class Menu < Page::Base + module Menu + class Admin < Page::Base def go_to_license click_link 'License' end diff --git a/qa/qa/page/main/menu.rb b/qa/qa/page/menu/main.rb index bc9c4ec1215..b94c2c6c23d 100644 --- a/qa/qa/page/main/menu.rb +++ b/qa/qa/page/menu/main.rb @@ -1,7 +1,7 @@ module QA module Page - module Main - class Menu < Page::Base + module Menu + class Main < Page::Base def go_to_groups within_top_menu { click_link 'Groups' } end diff --git a/qa/qa/page/menu/side.rb b/qa/qa/page/menu/side.rb new file mode 100644 index 00000000000..6c25aba4bac --- /dev/null +++ b/qa/qa/page/menu/side.rb @@ -0,0 +1,29 @@ +module QA + module Page + module Menu + class Side < Page::Base + def click_repository_setting + hover_setting do + click_link('Repository') + end + end + + private + + def hover_setting + within_sidebar do + find('.nav-item-name', text: 'Settings').hover + + yield + end + end + + def within_sidebar + page.within('.sidebar-top-level-items') do + yield + end + end + end + end + end +end diff --git a/qa/qa/page/project/settings/common.rb b/qa/qa/page/project/settings/common.rb new file mode 100644 index 00000000000..5d1d5120929 --- /dev/null +++ b/qa/qa/page/project/settings/common.rb @@ -0,0 +1,17 @@ +module QA + module Page + module Project + module Settings + module Common + def expand(selector) + page.within('#content-body') do + find(selector).click + + yield + end + end + end + end + end + end +end diff --git a/qa/qa/page/project/settings/deploy_keys.rb b/qa/qa/page/project/settings/deploy_keys.rb new file mode 100644 index 00000000000..4028b8cccc5 --- /dev/null +++ b/qa/qa/page/project/settings/deploy_keys.rb @@ -0,0 +1,27 @@ +module QA + module Page + module Project + module Settings + class DeployKeys < Page::Base + def fill_key_title(title) + fill_in 'deploy_key_title', with: title + end + + def fill_key_value(key) + fill_in 'deploy_key_key', with: key + end + + def add_key + click_on 'Add key' + end + + def has_key_title?(title) + page.within('.deploy-keys') do + page.find('.title', text: title) + end + end + end + end + end + end +end diff --git a/qa/qa/page/project/settings/repository.rb b/qa/qa/page/project/settings/repository.rb new file mode 100644 index 00000000000..034b0d09c1c --- /dev/null +++ b/qa/qa/page/project/settings/repository.rb @@ -0,0 +1,17 @@ +module QA + module Page + module Project + module Settings + class Repository < Page::Base + include Common + + def expand_deploy_keys(&block) + expand('.qa-expand-deploy-keys') do + DeployKeys.perform(&block) + end + end + end + end + end + end +end diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index 220bb45741b..14b2a488760 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -38,22 +38,49 @@ module QA Capybara.register_driver :chrome do |app| capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( - 'chromeOptions' => { - 'args' => %w[headless no-sandbox disable-gpu window-size=1280,1680] + # This enables access to logs with `page.driver.manage.get_log(:browser)` + loggingPrefs: { + browser: "ALL", + client: "ALL", + driver: "ALL", + server: "ALL" } ) - Capybara::Selenium::Driver - .new(app, browser: :chrome, desired_capabilities: capabilities) - end + options = Selenium::WebDriver::Chrome::Options.new + options.add_argument("window-size=1240,1680") - Capybara::Screenshot.register_driver(:chrome) do |driver, path| - driver.browser.save_screenshot(path) + # Chrome won't work properly in a Docker container in sandbox mode + options.add_argument("no-sandbox") + + # Run headless by default unless CHROME_HEADLESS is false + if QA::Runtime::Env.chrome_headless? + options.add_argument("headless") + + # Chrome documentation says this flag is needed for now + # https://developers.google.com/web/updates/2017/04/headless-chrome#cli + options.add_argument("disable-gpu") + end + + # Disable /dev/shm use in CI. See https://gitlab.com/gitlab-org/gitlab-ee/issues/4252 + options.add_argument("disable-dev-shm-usage") if QA::Runtime::Env.running_in_ci? + + Capybara::Selenium::Driver.new( + app, + browser: :chrome, + desired_capabilities: capabilities, + options: options + ) end # Keep only the screenshots generated from the last failing test suite Capybara::Screenshot.prune_strategy = :keep_last_run + # From https://github.com/mattheworiordan/capybara-screenshot/issues/84#issuecomment-41219326 + Capybara::Screenshot.register_driver(:chrome) do |driver, path| + driver.browser.save_screenshot(path) + end + Capybara.configure do |config| config.default_driver = :chrome config.javascript_driver = :chrome diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb new file mode 100644 index 00000000000..d5c28e9a7db --- /dev/null +++ b/qa/qa/runtime/env.rb @@ -0,0 +1,15 @@ +module QA + module Runtime + module Env + extend self + + def chrome_headless? + (ENV['CHROME_HEADLESS'] =~ /^(false|no|0)$/i) != 0 + end + + def running_in_ci? + ENV['CI'] || ENV['CI_SERVER'] + end + end + end +end diff --git a/qa/qa/runtime/user.rb b/qa/qa/runtime/user.rb index 60027c89ab1..2832439d9e0 100644 --- a/qa/qa/runtime/user.rb +++ b/qa/qa/runtime/user.rb @@ -10,6 +10,17 @@ module QA def password ENV['GITLAB_PASSWORD'] || '5iveL!fe' end + + def ssh_key + <<~KEY.delete("\n") + ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFf6RYK3qu/RKF/3ndJmL5xgMLp3O9 + 6x8lTay+QGZ0+9FnnAXMdUqBq/ZU6d/gyMB4IaW3nHzM1w049++yAB6UPCzMB8Uo27K5 + /jyZCtj7Vm9PFNjF/8am1kp46c/SeYicQgQaSBdzIW3UDEa1Ef68qroOlvpi9PYZ/tA7 + M0YP0K5PXX+E36zaIRnJVMPT3f2k+GnrxtjafZrwFdpOP/Fol5BQLBgcsyiU+LM1SuaC + rzd8c9vyaTA1CxrkxaZh+buAi0PmdDtaDrHd42gqZkXCKavyvgM5o2CkQ5LJHCgzpXy0 + 5qNFzmThBSkb+XtoxbyagBiGbVZtSVow6Xa7qewz= dummy@gitlab.com + KEY + end end end end diff --git a/qa/qa/specs/features/login/standard_spec.rb b/qa/qa/specs/features/login/standard_spec.rb index 9eaa2b772e6..141ffa3cfb7 100644 --- a/qa/qa/specs/features/login/standard_spec.rb +++ b/qa/qa/specs/features/login/standard_spec.rb @@ -7,7 +7,7 @@ module QA # TODO, since `Signed in successfully` message was removed # this is the only way to tell if user is signed in correctly. # - Page::Main::Menu.perform do |menu| + Page::Menu::Main.perform do |menu| expect(menu).to have_personal_area end end diff --git a/qa/qa/specs/features/mattermost/group_create_spec.rb b/qa/qa/specs/features/mattermost/group_create_spec.rb index b3dbe44bf6e..2e27a285223 100644 --- a/qa/qa/specs/features/mattermost/group_create_spec.rb +++ b/qa/qa/specs/features/mattermost/group_create_spec.rb @@ -3,7 +3,7 @@ module QA scenario 'creating a group with a mattermost team' do Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } - Page::Main::Menu.act { go_to_groups } + Page::Menu::Main.act { go_to_groups } Page::Dashboard::Groups.perform do |page| page.go_to_new_group diff --git a/qa/qa/specs/features/project/add_deploy_key_spec.rb b/qa/qa/specs/features/project/add_deploy_key_spec.rb new file mode 100644 index 00000000000..43a85213501 --- /dev/null +++ b/qa/qa/specs/features/project/add_deploy_key_spec.rb @@ -0,0 +1,22 @@ +module QA + feature 'deploy keys support', :core do + given(:deploy_key_title) { 'deploy key title' } + given(:deploy_key_value) { Runtime::User.ssh_key } + + scenario 'user adds a deploy key' do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.act { sign_in_using_credentials } + + Factory::Resource::DeployKey.fabricate! do |deploy_key| + deploy_key.title = deploy_key_title + deploy_key.key = deploy_key_value + end + + Page::Project::Settings::Repository.perform do |setting| + setting.expand_deploy_keys do |page| + expect(page).to have_key_title(deploy_key_title) + end + end + end + end +end diff --git a/qa/qa/specs/features/repository/push_spec.rb b/qa/qa/specs/features/repository/push_spec.rb index e47c769b015..4f6ffe14c9f 100644 --- a/qa/qa/specs/features/repository/push_spec.rb +++ b/qa/qa/specs/features/repository/push_spec.rb @@ -5,15 +5,10 @@ module QA Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } - Factory::Resource::Project.fabricate! do |scenario| - scenario.name = 'project_with_code' - scenario.description = 'project with repository' - end - - Factory::Repository::Push.fabricate! do |scenario| - scenario.file_name = 'README.md' - scenario.file_content = '# This is test project' - scenario.commit_message = 'Add README.md' + Factory::Repository::Push.fabricate! do |push| + push.file_name = 'README.md' + push.file_content = '# This is a test project' + push.commit_message = 'Add README.md' end Page::Project::Show.act do @@ -22,7 +17,7 @@ module QA end expect(page).to have_content('README.md') - expect(page).to have_content('This is test project') + expect(page).to have_content('This is a test project') end end end diff --git a/qa/spec/factory/base_spec.rb b/qa/spec/factory/base_spec.rb new file mode 100644 index 00000000000..a3ba0176819 --- /dev/null +++ b/qa/spec/factory/base_spec.rb @@ -0,0 +1,88 @@ +describe QA::Factory::Base do + describe '.fabricate!' do + subject { Class.new(described_class) } + let(:factory) { spy('factory') } + let(:product) { spy('product') } + + before do + allow(QA::Factory::Product).to receive(:new).and_return(product) + end + + it 'instantiates the factory and calls factory method' do + expect(subject).to receive(:new).and_return(factory) + + subject.fabricate!('something') + + expect(factory).to have_received(:fabricate!).with('something') + end + + it 'returns fabrication product' do + allow(subject).to receive(:new).and_return(factory) + allow(factory).to receive(:fabricate!).and_return('something') + + result = subject.fabricate!('something') + + expect(result).to eq product + end + + it 'yields factory before calling factory method' do + allow(subject).to receive(:new).and_return(factory) + + subject.fabricate! do |factory| + factory.something! + end + + expect(factory).to have_received(:something!).ordered + expect(factory).to have_received(:fabricate!).ordered + end + end + + describe '.dependency' do + let(:dependency) { spy('dependency') } + + before do + stub_const('Some::MyDependency', dependency) + end + + subject do + Class.new(described_class) do + dependency Some::MyDependency, as: :mydep do |factory| + factory.something! + end + end + end + + it 'appends a new dependency and accessors' do + expect(subject.dependencies).to be_one + end + + it 'defines dependency accessors' do + expect(subject.new).to respond_to :mydep, :mydep= + end + end + + describe 'building dependencies' do + let(:dependency) { double('dependency') } + let(:instance) { spy('instance') } + + subject do + Class.new(described_class) do + dependency Some::MyDependency, as: :mydep + end + end + + before do + stub_const('Some::MyDependency', dependency) + + allow(subject).to receive(:new).and_return(instance) + allow(instance).to receive(:mydep).and_return(nil) + allow(QA::Factory::Product).to receive(:new) + end + + it 'builds all dependencies first' do + expect(dependency).to receive(:fabricate!).once + + subject.fabricate! + end + end +end diff --git a/qa/spec/factory/dependency_spec.rb b/qa/spec/factory/dependency_spec.rb new file mode 100644 index 00000000000..32405415126 --- /dev/null +++ b/qa/spec/factory/dependency_spec.rb @@ -0,0 +1,59 @@ +describe QA::Factory::Dependency do + let(:dependency) { spy('dependency' ) } + let(:factory) { spy('factory') } + let(:block) { spy('block') } + + let(:signature) do + double('signature', factory: dependency, block: block) + end + + subject do + described_class.new(:mydep, factory, signature) + end + + describe '#overridden?' do + it 'returns true if factory has overridden dependency' do + allow(factory).to receive(:mydep).and_return('something') + + expect(subject).to be_overridden + end + + it 'returns false if dependency has not been overridden' do + allow(factory).to receive(:mydep).and_return(nil) + + expect(subject).not_to be_overridden + end + end + + describe '#build!' do + context 'when dependency has been overridden' do + before do + allow(subject).to receive(:overridden?).and_return(true) + end + + it 'does not fabricate dependency' do + subject.build! + + expect(dependency).not_to have_received(:fabricate!) + end + end + + context 'when dependency has not been overridden' do + before do + allow(subject).to receive(:overridden?).and_return(false) + end + + it 'fabricates dependency' do + subject.build! + + expect(dependency).to have_received(:fabricate!) + end + + it 'sets product in the factory' do + subject.build! + + expect(factory).to have_received(:mydep=).with(dependency) + end + end + end +end diff --git a/qa/spec/factory/product_spec.rb b/qa/spec/factory/product_spec.rb new file mode 100644 index 00000000000..3d9e86a641b --- /dev/null +++ b/qa/spec/factory/product_spec.rb @@ -0,0 +1,44 @@ +describe QA::Factory::Product do + let(:factory) { spy('factory') } + let(:product) { spy('product') } + + describe '.populate!' do + it 'instantiates and yields factory' do + expect(described_class).to receive(:new).with(factory) + + described_class.populate!(factory) do |instance| + instance.something = 'string' + end + + expect(factory).to have_received(:something=).with('string') + end + + it 'returns a fabrication product' do + expect(described_class).to receive(:new) + .with(factory).and_return(product) + + result = described_class.populate!(factory) do |instance| + instance.something = 'string' + end + + expect(result).to be product + end + + it 'raises unless block given' do + expect { described_class.populate!(factory) } + .to raise_error ArgumentError + end + end + + describe '.visit!' do + it 'makes it possible to visit fabrication product' do + allow_any_instance_of(described_class) + .to receive(:current_url).and_return('some url') + allow_any_instance_of(described_class) + .to receive(:visit).and_return('visited some url') + + expect(described_class.new(factory).visit!) + .to eq 'visited some url' + end + end +end diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb new file mode 100644 index 00000000000..57a72a04507 --- /dev/null +++ b/qa/spec/runtime/env_spec.rb @@ -0,0 +1,64 @@ +describe QA::Runtime::Env do + before do + allow(ENV).to receive(:[]).and_call_original + end + + describe '.chrome_headless?' do + context 'when there is an env variable set' do + it 'returns false when falsey values specified' do + stub_env('CHROME_HEADLESS', 'false') + expect(described_class.chrome_headless?).to be_falsey + + stub_env('CHROME_HEADLESS', 'no') + expect(described_class.chrome_headless?).to be_falsey + + stub_env('CHROME_HEADLESS', '0') + expect(described_class.chrome_headless?).to be_falsey + end + + it 'returns true when anything else specified' do + stub_env('CHROME_HEADLESS', 'true') + expect(described_class.chrome_headless?).to be_truthy + + stub_env('CHROME_HEADLESS', '1') + expect(described_class.chrome_headless?).to be_truthy + + stub_env('CHROME_HEADLESS', 'anything') + expect(described_class.chrome_headless?).to be_truthy + end + end + + context 'when there is no env variable set' do + it 'returns the default, true' do + stub_env('CHROME_HEADLESS', nil) + expect(described_class.chrome_headless?).to be_truthy + end + end + end + + describe '.running_in_ci?' do + context 'when there is an env variable set' do + it 'returns true if CI' do + stub_env('CI', 'anything') + expect(described_class.running_in_ci?).to be_truthy + end + + it 'returns true if CI_SERVER' do + stub_env('CI_SERVER', 'anything') + expect(described_class.running_in_ci?).to be_truthy + end + end + + context 'when there is no env variable set' do + it 'returns true' do + stub_env('CI', nil) + stub_env('CI_SERVER', nil) + expect(described_class.running_in_ci?).to be_falsey + end + end + end + + def stub_env(name, value) + allow(ENV).to receive(:[]).with(name).and_return(value) + end +end |