2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'rubocop_spec_helper'
|
2020-05-24 23:13:21 +05:30
|
|
|
require_relative '../../../../rubocop/cop/gitlab/json'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::Gitlab::Json do
|
2021-10-27 15:23:28 +05:30
|
|
|
context 'when ::JSON is called' do
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'registers an offense' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo
|
|
|
|
def bar
|
|
|
|
JSON.parse('{ "foo": "bar" }')
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `JSON` directly. [...]
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
RUBY
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
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
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|