debian-mirror-gitlab/spec/rubocop/cop/gitlab/json_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
868 B
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_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
2020-05-24 23:13:21 +05:30
subject(:cop) { described_class.new }
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