diff options
author | Stan Hu <stanhu@gmail.com> | 2019-04-28 09:38:05 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-04-29 16:14:53 +0300 |
commit | fad99d934f73536929c4a12e25308473b52769b5 (patch) | |
tree | ead2f1bb4608d3db4713ce1bf8e80a4f0e637318 /spec | |
parent | b02458ef52ac3e61d3c8b924e092e956375c15f7 (diff) |
Add Rubocop rule to ban include ActionView::Context
Diffstat (limited to 'spec')
-rw-r--r-- | spec/rubocop/cop/include_action_view_context_spec.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/rubocop/cop/include_action_view_context_spec.rb b/spec/rubocop/cop/include_action_view_context_spec.rb new file mode 100644 index 00000000000..c888555b54f --- /dev/null +++ b/spec/rubocop/cop/include_action_view_context_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../rubocop/cop/include_action_view_context' + +describe RuboCop::Cop::IncludeActionViewContext do + include CopHelper + + subject(:cop) { described_class.new } + + context 'when `ActionView::Context` is included' do + let(:source) { 'include ActionView::Context' } + let(:correct_source) { 'include ::Gitlab::ActionViewOutput::Context' } + + it 'registers an offense' do + inspect_source(source) + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + expect(cop.highlights).to eq(['ActionView::Context']) + end + end + + it 'autocorrects to the right version' do + autocorrected = autocorrect_source(source) + + expect(autocorrected).to eq(correct_source) + end + end + + context 'when `ActionView::Context` is not included' do + it 'registers no offense' do + inspect_source('include Context') + + aggregate_failures do + expect(cop.offenses.size).to eq(0) + end + end + end +end |