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

json_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: e4ec107747d8356536b50125e64cccf0252fa5bd (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
# frozen_string_literal: true

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

RSpec.describe RuboCop::Cop::Gitlab::Json do
  context 'when ::JSON is called' do
    it 'registers an offense' do
      expect_offense(<<~RUBY)
        class Foo
          def bar
            JSON.parse('{ "foo": "bar" }')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `JSON` directly. [...]
          end
        end
      RUBY
    end
  end

  context 'when ActiveSupport::JSON is called' do
    it 'registers an offense' do
      expect_offense(<<~RUBY)
        class Foo
          def bar
            ActiveSupport::JSON.parse('{ "foo": "bar" }')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `JSON` directly. [...]
          end
        end
      RUBY
    end
  end
end