2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
require 'fast_spec_helper'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/rspec/env_assignment'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::RSpec::EnvAssignment do
|
2020-05-24 23:13:21 +05:30
|
|
|
offense_call_single_quotes_key = %(ENV['FOO'] = 'bar').freeze
|
|
|
|
offense_call_double_quotes_key = %(ENV["FOO"] = 'bar').freeze
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
let(:source_file) { 'spec/foo_spec.rb' }
|
|
|
|
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
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
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect_correction(<<~CODE)
|
|
|
|
#{autocorrected_content}
|
|
|
|
CODE
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'with a key using single quotes' do
|
2021-03-11 19:13:27 +05:30
|
|
|
it_behaves_like 'an offensive and correction ENV#[]= call', offense_call_single_quotes_key, %(stub_env('FOO', 'bar'))
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'with a key using double quotes' do
|
2021-03-11 19:13:27 +05:30
|
|
|
it_behaves_like 'an offensive and correction ENV#[]= call', offense_call_double_quotes_key, %(stub_env("FOO", 'bar'))
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|