Commit 06c3c71b authored by Robert Speicher's avatar Robert Speicher

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
parents 1585608b 1761da51
Pipeline #6991910 failed with stages
in 84 minutes and 1 second
......@@ -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"
......
# -*- 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) }
......
......@@ -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]
......
......@@ -49,8 +49,4 @@ module ApiHelpers
''
end
end
def json_response
@_json_response ||= JSON.parse(response.body)
end
end
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment