diff options
Diffstat (limited to 'spec/rubocop/cop/rspec/env_assignment_spec.rb')
-rw-r--r-- | spec/rubocop/cop/rspec/env_assignment_spec.rb | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/spec/rubocop/cop/rspec/env_assignment_spec.rb b/spec/rubocop/cop/rspec/env_assignment_spec.rb index 07afd30fc90..cc132d1532a 100644 --- a/spec/rubocop/cop/rspec/env_assignment_spec.rb +++ b/spec/rubocop/cop/rspec/env_assignment_spec.rb @@ -3,13 +3,9 @@ require 'fast_spec_helper' require 'rubocop' -require 'rubocop/rspec/support' - require_relative '../../../../rubocop/cop/rspec/env_assignment' RSpec.describe RuboCop::Cop::RSpec::EnvAssignment do - include CopHelper - offense_call_single_quotes_key = %(ENV['FOO'] = 'bar').freeze offense_call_double_quotes_key = %(ENV["FOO"] = 'bar').freeze @@ -17,31 +13,24 @@ RSpec.describe RuboCop::Cop::RSpec::EnvAssignment do subject(:cop) { described_class.new } - shared_examples 'an offensive ENV#[]= call' do |content| - it "registers an offense for `#{content}`" do - inspect_source(content, source_file) - - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - expect(cop.highlights).to eq([content]) - end - end - - shared_examples 'an autocorrected ENV#[]= call' do |content, autocorrected_content| - it "registers an offense for `#{content}` and autocorrects it to `#{autocorrected_content}`" do - autocorrected = autocorrect_source(content, source_file) + 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 - expect(autocorrected).to eql(autocorrected_content) + expect_correction(<<~CODE) + #{autocorrected_content} + CODE end end context 'with a key using single quotes' do - it_behaves_like 'an offensive ENV#[]= call', offense_call_single_quotes_key - it_behaves_like 'an autocorrected ENV#[]= call', offense_call_single_quotes_key, %(stub_env('FOO', 'bar')) + it_behaves_like 'an offensive and correction ENV#[]= call', offense_call_single_quotes_key, %(stub_env('FOO', 'bar')) end context 'with a key using double quotes' do - it_behaves_like 'an offensive ENV#[]= call', offense_call_double_quotes_key - it_behaves_like 'an autocorrected ENV#[]= call', offense_call_double_quotes_key, %(stub_env("FOO", 'bar')) + it_behaves_like 'an offensive and correction ENV#[]= call', offense_call_double_quotes_key, %(stub_env("FOO", 'bar')) end end |