Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop/cop/rake/require_spec.rb')
-rw-r--r--spec/rubocop/cop/rake/require_spec.rb108
1 files changed, 69 insertions, 39 deletions
diff --git a/spec/rubocop/cop/rake/require_spec.rb b/spec/rubocop/cop/rake/require_spec.rb
index bb8c6a1f063..de484643d6e 100644
--- a/spec/rubocop/cop/rake/require_spec.rb
+++ b/spec/rubocop/cop/rake/require_spec.rb
@@ -7,54 +7,84 @@ require_relative '../../../../rubocop/cop/rake/require'
RSpec.describe RuboCop::Cop::Rake::Require do
let(:msg) { described_class::MSG }
- it 'registers an offenses for require methods' do
- expect_offense(<<~RUBY)
- require 'json'
- ^^^^^^^^^^^^^^ #{msg}
- require_relative 'gitlab/json'
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
- RUBY
+ describe '#in_rake_file?' do
+ context 'in a Rake file' do
+ let(:node) { double(location: double(expression: double(source_buffer: double(name: 'foo/bar.rake')))) } # rubocop:disable RSpec/VerifiedDoubles
+
+ it { expect(subject.__send__(:in_rake_file?, node)).to be(true) }
+ end
+
+ context 'when outside of a Rake file' do
+ let(:node) { double(location: double(expression: double(source_buffer: double(name: 'foo/bar.rb')))) } # rubocop:disable RSpec/VerifiedDoubles
+
+ it { expect(subject.__send__(:in_rake_file?, node)).to be(false) }
+ end
end
- it 'does not register offense inside `task` definition' do
- expect_no_offenses(<<~RUBY)
- task :parse do
+ context 'in a Rake file' do
+ before do
+ allow(cop).to receive(:in_rake_file?).and_return(true)
+ end
+
+ it 'registers an offenses for require methods' do
+ expect_offense(<<~RUBY)
require 'json'
- end
+ ^^^^^^^^^^^^^^ #{msg}
+ require_relative 'gitlab/json'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
+ RUBY
+ end
- namespace :some do
- task parse: :env do
- require_relative 'gitlab/json'
+ it 'does not register offense inside `task` definition' do
+ expect_no_offenses(<<~RUBY)
+ task :parse do
+ require 'json'
end
- end
- RUBY
- end
- it 'does not register offense inside a block definition' do
- expect_no_offenses(<<~RUBY)
- RSpec::Core::RakeTask.new(:parse_json) do |t, args|
- require 'json'
- end
- RUBY
- end
+ namespace :some do
+ task parse: :env do
+ require_relative 'gitlab/json'
+ end
+ end
+ RUBY
+ end
- it 'does not register offense inside a method definition' do
- expect_no_offenses(<<~RUBY)
- def load_deps
- require 'json'
- end
+ it 'does not register offense inside a block definition' do
+ expect_no_offenses(<<~RUBY)
+ RSpec::Core::RakeTask.new(:parse_json) do |t, args|
+ require 'json'
+ end
+ RUBY
+ end
+
+ it 'does not register offense inside a method definition' do
+ expect_no_offenses(<<~RUBY)
+ def load_deps
+ require 'json'
+ end
- task :parse do
- load_deps
- end
- RUBY
+ task :parse do
+ load_deps
+ end
+ RUBY
+ end
+
+ it 'does not register offense when require task related files' do
+ expect_no_offenses(<<~RUBY)
+ require 'rubocop/rake_tasks'
+ require 'gettext_i18n_rails/tasks'
+ require_relative '../../rubocop/check_graceful_task'
+ RUBY
+ end
end
- it 'does not register offense when require task related files' do
- expect_no_offenses(<<~RUBY)
- require 'rubocop/rake_tasks'
- require 'gettext_i18n_rails/tasks'
- require_relative '../../rubocop/check_graceful_task'
- RUBY
+ context 'when outside of a Rake file' do
+ before do
+ allow(cop).to receive(:in_rake_file?).and_return(false)
+ end
+
+ it 'registers an offenses for require methods' do
+ expect_no_offenses("require 'json'")
+ end
end
end