diff options
author | Robert Speicher <robert@gitlab.com> | 2017-03-13 18:01:26 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-03-13 18:01:26 +0000 |
commit | 06c3c71bb8b15e4cad43cf890012ac869248b861 (patch) | |
tree | 1613caf084433ef5a1ce43564f913cc45c56e148 | |
parent | 1585608bdcf932b58d301a7943c01ea824ea524e (diff) | |
parent | 1761da5152e460549e0e827990ea4f36d097db33 (diff) | |
download | gitlab-ce-06c3c71bb8b15e4cad43cf890012ac869248b861.tar.gz |
Merge branch '29242-fix-api-specs-potential-weird-failures-on-retries' into 'master'
Implement `json_response` as a `let` variable
Closes #29242
See merge request !9825
-rw-r--r-- | .gitlab-ci.yml | 2 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 4 | ||||
-rw-r--r-- | spec/spec_helper.rb | 13 | ||||
-rw-r--r-- | spec/support/api_helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/json_response_helpers.rb | 9 |
5 files changed, 24 insertions, 8 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index deeb01f9a3c..db3d25195dc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,8 +7,6 @@ cache: variables: MYSQL_ALLOW_EMPTY_PASSWORD: "1" - # retry tests only in CI environment - RSPEC_RETRY_RETRY_COUNT: "3" RAILS_ENV: "test" SIMPLECOV: "true" SETUP_DB: "true" diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index b4b23617498..c481b7e72b1 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- require 'spec_helper' -describe API::Projects, api: true do - include ApiHelpers +describe API::Projects, :api do include Gitlab::CurrentSettings + let(:user) { create(:user) } let(:user2) { create(:user) } let(:user3) { create(:user) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5fda7c63cdb..ceb3209331f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,14 +43,27 @@ RSpec.configure do |config| config.include ActiveSupport::Testing::TimeHelpers config.include StubGitlabCalls config.include StubGitlabData + config.include ApiHelpers, :api config.infer_spec_type_from_file_location! + + config.define_derived_metadata(file_path: %r{/spec/requests/(ci/)?api/}) do |metadata| + metadata[:api] = true + end + config.raise_errors_for_deprecations! config.before(:suite) do TestEnv.init end + if ENV['CI'] + # Retry only on feature specs that use JS + config.around :each, :js do |ex| + ex.run_with_retry retry: 3 + end + end + config.around(:each, :caching) do |example| caching_store = Rails.cache Rails.cache = ActiveSupport::Cache::MemoryStore.new if example.metadata[:caching] diff --git a/spec/support/api_helpers.rb b/spec/support/api_helpers.rb index ae6e708cf87..35d1e1cfc7d 100644 --- a/spec/support/api_helpers.rb +++ b/spec/support/api_helpers.rb @@ -49,8 +49,4 @@ module ApiHelpers '' end end - - def json_response - @_json_response ||= JSON.parse(response.body) - end end diff --git a/spec/support/json_response_helpers.rb b/spec/support/json_response_helpers.rb new file mode 100644 index 00000000000..e8d2ef2d7f0 --- /dev/null +++ b/spec/support/json_response_helpers.rb @@ -0,0 +1,9 @@ +shared_context 'JSON response' do + let(:json_response) { JSON.parse(response.body) } +end + +RSpec.configure do |config| + config.include_context 'JSON response', type: :controller + config.include_context 'JSON response', type: :request + config.include_context 'JSON response', :api +end |