diff options
-rw-r--r-- | qa/qa.rb | 8 | ||||
-rw-r--r-- | qa/qa/factory/product.rb | 1 | ||||
-rw-r--r-- | qa/qa/runtime/api.rb | 16 | ||||
-rw-r--r-- | qa/qa/runtime/browser.rb | 4 | ||||
-rw-r--r-- | qa/qa/specs/features/api/users_spec.rb | 1 | ||||
-rw-r--r-- | qa/qa/support/stub_env.rb | 40 | ||||
-rw-r--r-- | qa/spec/runtime/api_client_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/runtime/api_request_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/runtime/env_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/spec_helper.rb | 2 | ||||
-rw-r--r-- | qa/spec/support/stub_env.rb | 38 |
11 files changed, 53 insertions, 63 deletions
@@ -147,14 +147,6 @@ module QA autoload :Config, 'qa/specs/config' autoload :Runner, 'qa/specs/runner' end - - - ## - # Classes that provide support methods - # - module Support - autoload :StubENV, 'qa/support/stub_env' - end end QA::Runtime::Release.extend_autoloads! diff --git a/qa/qa/factory/product.rb b/qa/qa/factory/product.rb index 937bae7ac11..d004e642f9b 100644 --- a/qa/qa/factory/product.rb +++ b/qa/qa/factory/product.rb @@ -4,7 +4,6 @@ module QA module Factory class Product include Capybara::DSL - attr_reader :factory Attribute = Struct.new(:name, :block) diff --git a/qa/qa/runtime/api.rb b/qa/qa/runtime/api.rb index ee206fe299c..89b8a4a8b2d 100644 --- a/qa/qa/runtime/api.rb +++ b/qa/qa/runtime/api.rb @@ -24,13 +24,13 @@ module QA end end - def create_personal_access_token - Runtime::Browser.visit(@address, Page::Main::Login) - Page::Main::Login.act { sign_in_using_credentials } - token = Factory::Resource::PersonalAccessToken.fabricate!.access_token - Page::Menu::Main.act { sign_out } + private - token + def create_personal_access_token + Runtime::Browser.visit(@address, Page::Main::Login) do + Page::Main::Login.act { sign_in_using_credentials } + Factory::Resource::PersonalAccessToken.fabricate!.access_token + end end end @@ -61,7 +61,7 @@ module QA # # Returns the relative path to the requested API resource def request_path(path, version: API_VERSION, personal_access_token: nil, oauth_access_token: nil) - full_path = "/api/#{version}#{path}" + full_path = File.join('/api', version, path) if oauth_access_token query_string = "access_token=#{oauth_access_token}" @@ -70,7 +70,7 @@ module QA end if query_string - full_path << (path.index('?') ? '&' : '?') + full_path << (path.include?('?') ? '&' : '?') full_path << query_string end diff --git a/qa/qa/runtime/browser.rb b/qa/qa/runtime/browser.rb index 7882c8a0947..0e0efca1683 100644 --- a/qa/qa/runtime/browser.rb +++ b/qa/qa/runtime/browser.rb @@ -24,9 +24,7 @@ module QA # based on `Runtime::Scenario#something_address`. # def visit(address, page, &block) - Browser::Session.new(address, page).tap do |session| - session.perform(&block) - end + Browser::Session.new(address, page).perform(&block) end def self.visit(address, page, &block) diff --git a/qa/qa/specs/features/api/users_spec.rb b/qa/qa/specs/features/api/users_spec.rb index 1991b650608..fcaba0a0240 100644 --- a/qa/qa/specs/features/api/users_spec.rb +++ b/qa/qa/specs/features/api/users_spec.rb @@ -25,6 +25,7 @@ module QA scenario 'submit request with an invalid token' do request = Runtime::API::Request.new(@api_client, '/users', personal_access_token: 'invalid') + get request.url expect_status(401) diff --git a/qa/qa/support/stub_env.rb b/qa/qa/support/stub_env.rb deleted file mode 100644 index 74beb62151f..00000000000 --- a/qa/qa/support/stub_env.rb +++ /dev/null @@ -1,40 +0,0 @@ -# Inspired by https://github.com/ljkbennett/stub_env/blob/master/lib/stub_env/helpers.rb -module QA - module Support - module StubENV - def stub_env(key_or_hash, value = nil) - init_stub unless env_stubbed? - - if key_or_hash.is_a? Hash - key_or_hash.each { |k, v| add_stubbed_value(k, v) } - else - add_stubbed_value key_or_hash, value - end - end - - private - - STUBBED_KEY = '__STUBBED__'.freeze - - def add_stubbed_value(key, value) - allow(ENV).to receive(:[]).with(key).and_return(value) - allow(ENV).to receive(:key?).with(key).and_return(true) - allow(ENV).to receive(:fetch).with(key).and_return(value) - allow(ENV).to receive(:fetch).with(key, anything()) do |_, default_val| - value || default_val - end - end - - def env_stubbed? - ENV[STUBBED_KEY] - end - - def init_stub - allow(ENV).to receive(:[]).and_call_original - allow(ENV).to receive(:key?).and_call_original - allow(ENV).to receive(:fetch).and_call_original - add_stubbed_value(STUBBED_KEY, true) - end - end - end -end
\ No newline at end of file diff --git a/qa/spec/runtime/api_client_spec.rb b/qa/spec/runtime/api_client_spec.rb index ff2a4c3b9b0..d497d8839b8 100644 --- a/qa/spec/runtime/api_client_spec.rb +++ b/qa/spec/runtime/api_client_spec.rb @@ -1,5 +1,5 @@ describe QA::Runtime::API::Client do - include QA::Support::StubENV + include Support::StubENV describe 'initialization' do it 'defaults to :gitlab address' do diff --git a/qa/spec/runtime/api_request_spec.rb b/qa/spec/runtime/api_request_spec.rb index ba1b8066673..5a67611c0e3 100644 --- a/qa/spec/runtime/api_request_spec.rb +++ b/qa/spec/runtime/api_request_spec.rb @@ -1,5 +1,5 @@ describe QA::Runtime::API::Request do - include QA::Support::StubENV + include Support::StubENV before do stub_env('PERSONAL_ACCESS_TOKEN', 'a_token') diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index 3914a514244..103573db6be 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -1,5 +1,5 @@ describe QA::Runtime::Env do - include QA::Support::StubENV + include Support::StubENV describe '.chrome_headless?' do context 'when there is an env variable set' do diff --git a/qa/spec/spec_helper.rb b/qa/spec/spec_helper.rb index 64d06ef6558..57c20aba1d0 100644 --- a/qa/spec/spec_helper.rb +++ b/qa/spec/spec_helper.rb @@ -1,5 +1,7 @@ require_relative '../qa' +Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f } + RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true diff --git a/qa/spec/support/stub_env.rb b/qa/spec/support/stub_env.rb new file mode 100644 index 00000000000..bc8f3a5e22e --- /dev/null +++ b/qa/spec/support/stub_env.rb @@ -0,0 +1,38 @@ +# Inspired by https://github.com/ljkbennett/stub_env/blob/master/lib/stub_env/helpers.rb +module Support + module StubENV + def stub_env(key_or_hash, value = nil) + init_stub unless env_stubbed? + + if key_or_hash.is_a? Hash + key_or_hash.each { |k, v| add_stubbed_value(k, v) } + else + add_stubbed_value key_or_hash, value + end + end + + private + + STUBBED_KEY = '__STUBBED__'.freeze + + def add_stubbed_value(key, value) + allow(ENV).to receive(:[]).with(key).and_return(value) + allow(ENV).to receive(:key?).with(key).and_return(true) + allow(ENV).to receive(:fetch).with(key).and_return(value) + allow(ENV).to receive(:fetch).with(key, anything()) do |_, default_val| + value || default_val + end + end + + def env_stubbed? + ENV[STUBBED_KEY] + end + + def init_stub + allow(ENV).to receive(:[]).and_call_original + allow(ENV).to receive(:key?).and_call_original + allow(ENV).to receive(:fetch).and_call_original + add_stubbed_value(STUBBED_KEY, true) + end + end +end |