Implement `json_response` as a `let` variable
This is not a good idea to memoize `json_response` using an instance variable because `rspec-retry` doesn't clear instance variables on retries, only `let` variables. This will avoid issues where retries would fail on a different line that the original failure, blurrying what's the real failure. Also, automatically add api: true to specs under /spec/requests/(ci/)?api/, and include JsonHelpers in controller, request and API specs. Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
1d4b11f338
commit
5f7592d538
|
@ -1,9 +1,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe API::Projects, api: true do
|
describe API::Projects, :api do
|
||||||
include ApiHelpers
|
|
||||||
include Gitlab::CurrentSettings
|
include Gitlab::CurrentSettings
|
||||||
|
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:user2) { create(:user) }
|
let(:user2) { create(:user) }
|
||||||
let(:user3) { create(:user) }
|
let(:user3) { create(:user) }
|
||||||
|
|
|
@ -43,8 +43,14 @@ RSpec.configure do |config|
|
||||||
config.include ActiveSupport::Testing::TimeHelpers
|
config.include ActiveSupport::Testing::TimeHelpers
|
||||||
config.include StubGitlabCalls
|
config.include StubGitlabCalls
|
||||||
config.include StubGitlabData
|
config.include StubGitlabData
|
||||||
|
config.include ApiHelpers, :api
|
||||||
|
|
||||||
config.infer_spec_type_from_file_location!
|
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.raise_errors_for_deprecations!
|
||||||
|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
|
|
|
@ -49,8 +49,4 @@ module ApiHelpers
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def json_response
|
|
||||||
@_json_response ||= JSON.parse(response.body)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue