2019-10-29 12:06:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 06:08:43 +00:00
|
|
|
require 'fast_spec_helper'
|
2018-03-13 22:38:25 +00:00
|
|
|
require_relative '../../../../rubocop/cop/gitlab/httparty'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::Gitlab::HTTParty do # rubocop:disable RSpec/FilePath
|
2018-03-13 22:38:25 +00:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2021-01-26 18:09:30 +00:00
|
|
|
shared_examples('registering include offense') do
|
2018-03-13 22:38:25 +00:00
|
|
|
it 'registers an offense when the class includes HTTParty' do
|
2021-01-26 18:09:30 +00:00
|
|
|
expect_offense(source)
|
2018-03-13 22:38:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-26 18:09:30 +00:00
|
|
|
shared_examples('registering call offense') do
|
2018-03-13 22:38:25 +00:00
|
|
|
it 'registers an offense when the class calls HTTParty' do
|
2021-01-26 18:09:30 +00:00
|
|
|
expect_offense(source)
|
2018-03-13 22:38:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when source is a regular module' do
|
2021-01-26 18:09:30 +00:00
|
|
|
it_behaves_like 'registering include offense' do
|
2018-03-13 22:38:25 +00:00
|
|
|
let(:source) do
|
|
|
|
<<~RUBY
|
|
|
|
module M
|
|
|
|
include HTTParty
|
2021-01-26 18:09:30 +00:00
|
|
|
^^^^^^^^^^^^^^^^ Avoid including `HTTParty` directly. [...]
|
2018-03-13 22:38:25 +00:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when source is a regular class' do
|
2021-01-26 18:09:30 +00:00
|
|
|
it_behaves_like 'registering include offense' do
|
2018-03-13 22:38:25 +00:00
|
|
|
let(:source) do
|
|
|
|
<<~RUBY
|
|
|
|
class Foo
|
|
|
|
include HTTParty
|
2021-01-26 18:09:30 +00:00
|
|
|
^^^^^^^^^^^^^^^^ Avoid including `HTTParty` directly. [...]
|
2018-03-13 22:38:25 +00:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when HTTParty is called' do
|
2021-01-26 18:09:30 +00:00
|
|
|
it_behaves_like 'registering call offense' do
|
2018-03-13 22:38:25 +00:00
|
|
|
let(:source) do
|
|
|
|
<<~RUBY
|
|
|
|
class Foo
|
|
|
|
def bar
|
|
|
|
HTTParty.get('http://example.com')
|
2021-01-26 18:09:30 +00:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `HTTParty` directly. [...]
|
2018-03-13 22:38:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|