2019-10-29 08:06:40 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 14:10:07 -04:00
|
|
|
require 'rubocop_spec_helper'
|
2017-10-11 07:25:40 -04:00
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/rspec/env_assignment'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::RSpec::EnvAssignment do
|
2021-03-25 23:09:21 -04:00
|
|
|
offense_call_single_quotes_key = %(ENV['FOO'] = 'bar')
|
|
|
|
offense_call_double_quotes_key = %(ENV["FOO"] = 'bar')
|
2017-10-11 07:25:40 -04:00
|
|
|
|
|
|
|
let(:source_file) { 'spec/foo_spec.rb' }
|
|
|
|
|
2021-02-09 01:09:21 -05:00
|
|
|
shared_examples 'an offensive and correction ENV#[]= call' do |content, autocorrected_content|
|
|
|
|
it "registers an offense for `#{content}` and corrects", :aggregate_failures do
|
|
|
|
expect_offense(<<~CODE)
|
|
|
|
#{content}
|
|
|
|
^^^^^^^^^^^^^^^^^^ Don't assign to ENV, use `stub_env` instead.
|
|
|
|
CODE
|
2017-10-11 07:25:40 -04:00
|
|
|
|
2021-02-09 01:09:21 -05:00
|
|
|
expect_correction(<<~CODE)
|
|
|
|
#{autocorrected_content}
|
|
|
|
CODE
|
2017-10-11 07:25:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-26 08:24:25 -04:00
|
|
|
context 'with a key using single quotes' do
|
2021-02-09 01:09:21 -05:00
|
|
|
it_behaves_like 'an offensive and correction ENV#[]= call', offense_call_single_quotes_key, %(stub_env('FOO', 'bar'))
|
2017-10-11 07:25:40 -04:00
|
|
|
end
|
|
|
|
|
2019-08-26 08:24:25 -04:00
|
|
|
context 'with a key using double quotes' do
|
2021-02-09 01:09:21 -05:00
|
|
|
it_behaves_like 'an offensive and correction ENV#[]= call', offense_call_double_quotes_key, %(stub_env("FOO", 'bar'))
|
2017-10-11 07:25:40 -04:00
|
|
|
end
|
|
|
|
end
|