debian-mirror-gitlab/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
require_relative '../../../../rubocop/cop/rspec/httparty_basic_auth'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::RSpec::HTTPartyBasicAuth do
2021-02-22 17:27:13 +05:30
subject(:cop) { described_class.new }
context 'when passing `basic_auth: { user: ... }`' do
2021-03-11 19:13:27 +05:30
it 'registers an offense and corrects', :aggregate_failures do
2021-02-22 17:27:13 +05:30
expect_offense(<<~SOURCE, 'spec/foo.rb')
HTTParty.put(
url,
basic_auth: { user: user, password: token },
^^^^ #{described_class::MESSAGE}
body: body
)
SOURCE
2021-03-11 19:13:27 +05:30
expect_correction(<<~SOURCE)
HTTParty.put(
url,
basic_auth: { username: user, password: token },
body: body
)
SOURCE
2021-02-22 17:27:13 +05:30
end
end
context 'when passing `basic_auth: { username: ... }`' do
2021-03-11 19:13:27 +05:30
it 'does not register an offense' do
2021-02-22 17:27:13 +05:30
expect_no_offenses(<<~SOURCE, 'spec/frontend/fixtures/foo.rb')
HTTParty.put(
url,
basic_auth: { username: user, password: token },
body: body
)
SOURCE
end
end
end