2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'rubocop_spec_helper'
|
2018-03-26 14:24:53 +05:30
|
|
|
require_relative '../../../../rubocop/cop/gitlab/httparty'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::Gitlab::HTTParty do # rubocop:disable RSpec/FilePath
|
2021-03-11 19:13:27 +05:30
|
|
|
shared_examples('registering include offense') do
|
2018-03-26 14:24:53 +05:30
|
|
|
it 'registers an offense when the class includes HTTParty' do
|
2021-03-11 19:13:27 +05:30
|
|
|
expect_offense(source)
|
2018-03-26 14:24:53 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
shared_examples('registering call offense') do
|
2018-03-26 14:24:53 +05:30
|
|
|
it 'registers an offense when the class calls HTTParty' do
|
2021-03-11 19:13:27 +05:30
|
|
|
expect_offense(source)
|
2018-03-26 14:24:53 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when source is a regular module' do
|
2021-03-11 19:13:27 +05:30
|
|
|
it_behaves_like 'registering include offense' do
|
2018-03-26 14:24:53 +05:30
|
|
|
let(:source) do
|
|
|
|
<<~RUBY
|
|
|
|
module M
|
|
|
|
include HTTParty
|
2021-03-11 19:13:27 +05:30
|
|
|
^^^^^^^^^^^^^^^^ Avoid including `HTTParty` directly. [...]
|
2018-03-26 14:24:53 +05:30
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when source is a regular class' do
|
2021-03-11 19:13:27 +05:30
|
|
|
it_behaves_like 'registering include offense' do
|
2018-03-26 14:24:53 +05:30
|
|
|
let(:source) do
|
|
|
|
<<~RUBY
|
|
|
|
class Foo
|
|
|
|
include HTTParty
|
2021-03-11 19:13:27 +05:30
|
|
|
^^^^^^^^^^^^^^^^ Avoid including `HTTParty` directly. [...]
|
2018-03-26 14:24:53 +05:30
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when HTTParty is called' do
|
2021-03-11 19:13:27 +05:30
|
|
|
it_behaves_like 'registering call offense' do
|
2018-03-26 14:24:53 +05:30
|
|
|
let(:source) do
|
|
|
|
<<~RUBY
|
|
|
|
class Foo
|
|
|
|
def bar
|
|
|
|
HTTParty.get('http://example.com')
|
2021-03-11 19:13:27 +05:30
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `HTTParty` directly. [...]
|
2018-03-26 14:24:53 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|