summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpereira2 <rpereira@gitlab.com>2019-02-04 21:37:07 +0530
committerrpereira2 <rpereira@gitlab.com>2019-02-06 21:04:37 +0530
commit98c96de9a0c3f3249d5b40e1b79abbbeafb617ea (patch)
tree43e06b9f57a94e7fa725828c9b0bd9a014da45f1
parent01bae1678d68a66f78e4c9c345ba565b40f4b021 (diff)
downloadgitlab-ce-98c96de9a0c3f3249d5b40e1b79abbbeafb617ea.tar.gz
Refactor specs to use let and subject better
-rw-r--r--spec/services/error_tracking/list_sentry_projects_service_spec.rb53
1 files changed, 22 insertions, 31 deletions
diff --git a/spec/services/error_tracking/list_sentry_projects_service_spec.rb b/spec/services/error_tracking/list_sentry_projects_service_spec.rb
index e41639b76c0..77b253be2a2 100644
--- a/spec/services/error_tracking/list_sentry_projects_service_spec.rb
+++ b/spec/services/error_tracking/list_sentry_projects_service_spec.rb
@@ -23,30 +23,33 @@ describe ErrorTracking::ListSentryProjectsService do
end
describe '#execute' do
+ let(:result) { subject.execute }
+
context 'with authorized user' do
+ let(:sentry_client) { spy(:sentry_client) }
+
before do
expect(project).to receive(:error_tracking_setting).at_least(:once)
.and_return(error_tracking_setting)
end
- it 'uses new api_url and token' do
- sentry_client = spy(:sentry_client)
-
- expect(Sentry::Client).to receive(:new)
- .with(new_api_host + 'api/0/projects/', new_token).and_return(sentry_client)
- expect(sentry_client).to receive(:list_projects).and_return([])
+ context 'call sentry client' do
+ it 'uses new api_url and token' do
+ expect(Sentry::Client).to receive(:new)
+ .with(new_api_host + 'api/0/projects/', new_token).and_return(sentry_client)
+ expect(sentry_client).to receive(:list_projects).and_return([])
- subject.execute
+ subject.execute
+ end
end
context 'sentry client raises exception' do
- it 'returns error response' do
+ before do
expect(error_tracking_setting).to receive(:list_sentry_projects)
.and_raise(Sentry::Client::Error, 'Sentry response error: 500')
+ end
- subject = described_class.new(project, user, params)
- result = subject.execute
-
+ it 'returns error response' do
expect(result[:message]).to eq('Sentry response error: 500')
expect(result[:http_status]).to eq(:bad_request)
end
@@ -60,17 +63,13 @@ describe ErrorTracking::ListSentryProjectsService do
)
end
- subject { described_class.new(project, user, params) }
-
before do
error_tracking_setting.enabled = false
end
it 'returns error' do
- result = subject.execute
-
- expect(error_tracking_setting).not_to be_valid
expect(result[:message]).to start_with('Api url is blocked')
+ expect(error_tracking_setting).not_to be_valid
end
end
@@ -83,21 +82,17 @@ describe ErrorTracking::ListSentryProjectsService do
end
it 'returns the projects' do
- result = subject.execute
-
expect(result).to eq(status: :success, projects: projects)
end
end
end
context 'with unauthorized user' do
- let(:unauthorized_user) { create(:user) }
-
- subject { described_class.new(project, unauthorized_user) }
+ before do
+ project.add_guest(user)
+ end
it 'returns error' do
- result = subject.execute
-
expect(result).to include(status: :error, message: 'access denied')
end
end
@@ -113,20 +108,16 @@ describe ErrorTracking::ListSentryProjectsService do
end
it 'ignores enabled flag' do
- result = subject.execute
-
expect(result).to include(status: :success, projects: [])
end
end
context 'error_tracking_setting is nil' do
+ let(:sentry_client) { spy(:sentry_client) }
+
before do
expect(project).to receive(:error_tracking_setting).at_least(:once)
.and_return(nil)
- end
-
- it 'builds a new error_tracking_setting' do
- sentry_client = spy(:sentry_client)
expect(Sentry::Client).to receive(:new)
.with(new_api_host + 'api/0/projects/', new_token)
@@ -134,9 +125,9 @@ describe ErrorTracking::ListSentryProjectsService do
expect(sentry_client).to receive(:list_projects)
.and_return([:project1, :project2])
+ end
- result = subject.execute
-
+ it 'builds a new error_tracking_setting' do
expect(result[:projects]).to eq([:project1, :project2])
expect(project.error_tracking_setting).to be_nil
end