summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop/cop')
-rw-r--r--spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb80
-rw-r--r--spec/rubocop/cop/line_break_around_conditional_block_spec.rb13
-rw-r--r--spec/rubocop/cop/migration/add_timestamps_spec.rb1
-rw-r--r--spec/rubocop/cop/migration/timestamps_spec.rb1
-rw-r--r--spec/rubocop/cop/scalability/file_uploads_spec.rb1
5 files changed, 96 insertions, 0 deletions
diff --git a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
new file mode 100644
index 00000000000..0ff06b431eb
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'rubocop'
+require 'rubocop/rspec/support'
+require_relative '../../../../rubocop/cop/gitlab/const_get_inherit_false'
+
+describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ context 'Object.const_get' do
+ it 'registers an offense with no 2nd argument' do
+ expect_offense(<<~PATTERN.strip_indent)
+ Object.const_get(:CONSTANT)
+ ^^^^^^^^^ Use inherit=false when using const_get.
+ PATTERN
+ end
+
+ it 'autocorrects' do
+ expect(autocorrect_source('Object.const_get(:CONSTANT)')).to eq('Object.const_get(:CONSTANT, false)')
+ end
+
+ context 'inherit=false' do
+ it 'does not register an offense' do
+ expect_no_offenses(<<~PATTERN.strip_indent)
+ Object.const_get(:CONSTANT, false)
+ PATTERN
+ end
+ end
+
+ context 'inherit=true' do
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN.strip_indent)
+ Object.const_get(:CONSTANT, true)
+ ^^^^^^^^^ Use inherit=false when using const_get.
+ PATTERN
+ end
+
+ it 'autocorrects' do
+ expect(autocorrect_source('Object.const_get(:CONSTANT, true)')).to eq('Object.const_get(:CONSTANT, false)')
+ end
+ end
+ end
+
+ context 'const_get for a nested class' do
+ it 'registers an offense on reload usage' do
+ expect_offense(<<~PATTERN.strip_indent)
+ Nested::Blog.const_get(:CONSTANT)
+ ^^^^^^^^^ Use inherit=false when using const_get.
+ PATTERN
+ end
+
+ it 'autocorrects' do
+ expect(autocorrect_source('Nested::Blag.const_get(:CONSTANT)')).to eq('Nested::Blag.const_get(:CONSTANT, false)')
+ end
+
+ context 'inherit=false' do
+ it 'does not register an offense' do
+ expect_no_offenses(<<~PATTERN.strip_indent)
+ Nested::Blog.const_get(:CONSTANT, false)
+ PATTERN
+ end
+ end
+
+ context 'inherit=true' do
+ it 'registers an offense if inherit is true' do
+ expect_offense(<<~PATTERN.strip_indent)
+ Nested::Blog.const_get(:CONSTANT, true)
+ ^^^^^^^^^ Use inherit=false when using const_get.
+ PATTERN
+ end
+
+ it 'autocorrects' do
+ expect(autocorrect_source('Nested::Blag.const_get(:CONSTANT, true)')).to eq('Nested::Blag.const_get(:CONSTANT, false)')
+ end
+ end
+ end
+end
diff --git a/spec/rubocop/cop/line_break_around_conditional_block_spec.rb b/spec/rubocop/cop/line_break_around_conditional_block_spec.rb
index 892b393c307..cc933ce12c8 100644
--- a/spec/rubocop/cop/line_break_around_conditional_block_spec.rb
+++ b/spec/rubocop/cop/line_break_around_conditional_block_spec.rb
@@ -132,6 +132,19 @@ describe RuboCop::Cop::LineBreakAroundConditionalBlock do
expect(cop.offenses).to be_empty
end
+ it "doesn't flag violation for #{conditional} preceded by a block definition with a comment" do
+ source = <<~RUBY
+ on_block(param_a) do |item| # a short comment
+ #{conditional} condition
+ do_something
+ end
+ end
+ RUBY
+ inspect_source(source)
+
+ expect(cop.offenses).to be_empty
+ end
+
it "doesn't flag violation for #{conditional} preceded by a block definition using brackets" do
source = <<~RUBY
on_block(param_a) { |item|
diff --git a/spec/rubocop/cop/migration/add_timestamps_spec.rb b/spec/rubocop/cop/migration/add_timestamps_spec.rb
index fae0177d5f5..33f1bb85af8 100644
--- a/spec/rubocop/cop/migration/add_timestamps_spec.rb
+++ b/spec/rubocop/cop/migration/add_timestamps_spec.rb
@@ -9,6 +9,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do
include CopHelper
subject(:cop) { described_class.new }
+
let(:migration_with_add_timestamps) do
%q(
class Users < ActiveRecord::Migration[4.2]
diff --git a/spec/rubocop/cop/migration/timestamps_spec.rb b/spec/rubocop/cop/migration/timestamps_spec.rb
index 1812818692a..cafe255dc9a 100644
--- a/spec/rubocop/cop/migration/timestamps_spec.rb
+++ b/spec/rubocop/cop/migration/timestamps_spec.rb
@@ -9,6 +9,7 @@ describe RuboCop::Cop::Migration::Timestamps do
include CopHelper
subject(:cop) { described_class.new }
+
let(:migration_with_timestamps) do
%q(
class Users < ActiveRecord::Migration[4.2]
diff --git a/spec/rubocop/cop/scalability/file_uploads_spec.rb b/spec/rubocop/cop/scalability/file_uploads_spec.rb
index 2a94fde5ba2..a35d423581c 100644
--- a/spec/rubocop/cop/scalability/file_uploads_spec.rb
+++ b/spec/rubocop/cop/scalability/file_uploads_spec.rb
@@ -10,6 +10,7 @@ describe RuboCop::Cop::Scalability::FileUploads do
include ExpectOffense
subject(:cop) { described_class.new }
+
let(:message) { 'Do not upload files without workhorse acceleration. Please refer to https://docs.gitlab.com/ee/development/uploads.html' }
context 'with required params' do