2020-04-27 18:09:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 06:08:43 +00:00
|
|
|
require 'fast_spec_helper'
|
2020-04-27 18:09:41 +00:00
|
|
|
require_relative '../../../../rubocop/cop/gitlab/json'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::Gitlab::Json do
|
2020-04-27 18:09:41 +00:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2021-07-22 12:10:04 +00:00
|
|
|
context 'when ::JSON is called' do
|
2021-01-26 18:09:30 +00:00
|
|
|
it 'registers an offense' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo
|
|
|
|
def bar
|
|
|
|
JSON.parse('{ "foo": "bar" }')
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `JSON` directly. [...]
|
2020-04-27 18:09:41 +00:00
|
|
|
end
|
2021-01-26 18:09:30 +00:00
|
|
|
end
|
|
|
|
RUBY
|
2020-04-27 18:09:41 +00:00
|
|
|
end
|
|
|
|
end
|
2021-07-22 12:10:04 +00:00
|
|
|
|
|
|
|
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-04-27 18:09:41 +00:00
|
|
|
end
|