diff --git a/spec/requests/api/artifacts_spec.rb b/spec/requests/api/artifacts_spec.rb
index 2b84c1a2072f3fb89f62eec9b136510a531ccac9..393b8f85402cfecf36688539ea6e1a9ce89fe92c 100644
--- a/spec/requests/api/artifacts_spec.rb
+++ b/spec/requests/api/artifacts_spec.rb
@@ -4,18 +4,9 @@ require_relative '../shared/artifacts_context'
 describe API::API, api: true  do
   include ApiHelpers
 
-  let(:user) { create(:user) }
-  let(:project) { create(:project) }
-  let(:pipeline) do
-    create(:ci_pipeline, project: project, sha: project.commit('fix').sha)
-  end
-  let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
-
-  before do
-    project.team << [user, :developer]
-  end
-
   describe 'GET /projects/:id/artifacts/:ref_name/:build_name' do
+    include_context 'artifacts from ref and build name'
+
     def path_from_ref(ref = pipeline.sha, build_name = build.name, _ = '')
       api("/projects/#{project.id}/artifacts/#{ref}/#{build_name}", user)
     end
diff --git a/spec/requests/projects/artifacts_controller_spec.rb b/spec/requests/projects/artifacts_controller_spec.rb
index 9722a9a1d64f671c6fb43f71b8623ba3bd8ba8b3..26f6ee8d2520041d9573e3ca303df3ff2775ee9d 100644
--- a/spec/requests/projects/artifacts_controller_spec.rb
+++ b/spec/requests/projects/artifacts_controller_spec.rb
@@ -2,19 +2,13 @@ require 'spec_helper'
 require_relative '../shared/artifacts_context'
 
 describe Projects::ArtifactsController do
-  let(:user) { create(:user) }
-  let(:project) { create(:project) }
-  let(:pipeline) do
-    create(:ci_pipeline, project: project, sha: project.commit('fix').sha)
-  end
-  let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
+  describe 'GET /:project/artifacts/:ref/:build_name/browse' do
+    include_context 'artifacts from ref and build name'
 
-  before do
-    login_as(user)
-    project.team << [user, :developer]
-  end
+    before do
+      login_as(user)
+    end
 
-  describe 'GET /:project/artifacts/:ref/:build_name/browse' do
     def path_from_ref(ref = pipeline.sha, build_name = build.name,
                       path = 'browse')
       search_namespace_project_artifacts_path(
diff --git a/spec/requests/shared/artifacts_context.rb b/spec/requests/shared/artifacts_context.rb
index 4333be6e1cd680eb4c24d2eebbcd1a2730a4f7de..03f7f248773f53de791bbd6887fa039f561f9069 100644
--- a/spec/requests/shared/artifacts_context.rb
+++ b/spec/requests/shared/artifacts_context.rb
@@ -1,4 +1,17 @@
-shared_context 'artifacts from ref with 404' do
+shared_context 'artifacts from ref and build name' do
+  let(:user) { create(:user) }
+  let(:project) { create(:project) }
+  let(:pipeline) do
+    create(:ci_pipeline, project: project, sha: project.commit('fix').sha)
+  end
+  let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
+
+  before do
+    project.team << [user, :developer]
+  end
+end
+
+shared_examples 'artifacts from ref with 404' do
   context 'has no such ref' do
     before do
       get path_from_ref('TAIL', build.name)
@@ -16,7 +29,7 @@ shared_context 'artifacts from ref with 404' do
   end
 end
 
-shared_context 'artifacts from ref with 302' do
+shared_examples 'artifacts from ref with 302' do
   context 'with sha' do
     before do
       get path_from_ref