summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-03-09 00:41:02 +0100
committerRémy Coutable <remy@rymai.me>2017-03-13 17:33:17 +0100
commit5f7592d53805b18fbbc2a117ab8b4d953b13dbb1 (patch)
treebdf58db80db8b2b9b1d88a3417ea915d66e2561c
parent1d4b11f3388ddd7cf0076f95ac26196f6949dc0b (diff)
downloadgitlab-ce-5f7592d53805b18fbbc2a117ab8b4d953b13dbb1.tar.gz
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>
-rw-r--r--spec/requests/api/projects_spec.rb4
-rw-r--r--spec/spec_helper.rb6
-rw-r--r--spec/support/api_helpers.rb4
-rw-r--r--spec/support/json_response_helpers.rb9
4 files changed, 17 insertions, 6 deletions
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..068984aee84 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -43,8 +43,14 @@ 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
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