Welcome to mirror list, hosted at ThFree Co, Russian Federation.

service_response_spec.rb « gitlab « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 84cf0dbff523e52aed9cfa03ff7b899945b42aba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/gitlab/service_response'

RSpec.describe RuboCop::Cop::Gitlab::ServiceResponse do
  subject(:cop) { described_class.new }

  it 'does not flag the `http_status:` param on a homonym method' do
    expect_no_offenses("MyClass.error(http_status: :ok)")
  end

  it 'does not flag calls without params' do
    expect_no_offenses('ServiceResponse.error')
  end

  it 'does not flag the offense when `http_status` is not used' do
    expect_no_offenses('ServiceResponse.error(message: "some error", reason: :bad_time)')
  end

  it 'flags the use of `http_status:` parameter in ServiceResponse in error' do
    expect_offense(<<~CODE, msg: described_class::MSG)
      ServiceResponse.error(message: "some error", http_status: :bad_request)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
    CODE
  end

  it 'flags the use of `http_status:` parameter in ServiceResponse in success' do
    expect_offense(<<~CODE, msg: described_class::MSG)
      ServiceResponse.success(message: "some error", http_status: :bad_request)
                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
    CODE
  end

  it 'flags the use of `http_status:` parameter in ServiceResponse in initializer' do
    expect_offense(<<~CODE, msg: described_class::MSG)
      ServiceResponse.new(message: "some error", http_status: :bad_request)
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
    CODE
  end
end