diff options
author | Rémy Coutable <remy@rymai.me> | 2017-09-19 17:25:42 +0200 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2017-12-22 08:34:44 -0600 |
commit | a2d39b80109f006ff63752cfaed5e458f9443d1d (patch) | |
tree | cc5a0f06ba04448dbf025dd95a6e39686343d256 /spec | |
parent | 299e04e318728d4ee5857379f8fb350c944a0b4e (diff) | |
download | gitlab-ce-a2d39b80109f006ff63752cfaed5e458f9443d1d.tar.gz |
Use gitlab-styles
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec')
29 files changed, 76 insertions, 707 deletions
diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 5ed6b017dee..71dc169c6a2 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -14,6 +14,7 @@ FactoryBot.define do trait :closed do state :closed + closed_at { Time.now } end factory :closed_issue, traits: [:closed] diff --git a/spec/rubocop/cop/active_record_dependent_spec.rb b/spec/rubocop/cop/active_record_dependent_spec.rb deleted file mode 100644 index 599a032bfc5..00000000000 --- a/spec/rubocop/cop/active_record_dependent_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'spec_helper' -require 'rubocop' -require 'rubocop/rspec/support' -require_relative '../../../rubocop/cop/active_record_dependent' - -describe RuboCop::Cop::ActiveRecordDependent do - include CopHelper - - subject(:cop) { described_class.new } - - context 'inside the app/models directory' do - it 'registers an offense when dependent: is used' do - allow(cop).to receive(:in_model?).and_return(true) - - inspect_source(cop, 'belongs_to :foo, dependent: :destroy') - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - end - end - end - - context 'outside the app/models directory' do - it 'does nothing' do - allow(cop).to receive(:in_model?).and_return(false) - - inspect_source(cop, 'belongs_to :foo, dependent: :destroy') - - expect(cop.offenses).to be_empty - end - end -end diff --git a/spec/rubocop/cop/active_record_serialize_spec.rb b/spec/rubocop/cop/active_record_serialize_spec.rb deleted file mode 100644 index b94b25cecd0..00000000000 --- a/spec/rubocop/cop/active_record_serialize_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'spec_helper' -require 'rubocop' -require 'rubocop/rspec/support' -require_relative '../../../rubocop/cop/active_record_serialize' - -describe RuboCop::Cop::ActiveRecordSerialize do - include CopHelper - - subject(:cop) { described_class.new } - - context 'inside the app/models directory' do - it 'registers an offense when serialize is used' do - allow(cop).to receive(:in_model?).and_return(true) - - inspect_source(cop, 'serialize :foo') - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - end - end - end - - context 'outside the app/models directory' do - it 'does nothing' do - allow(cop).to receive(:in_model?).and_return(false) - - inspect_source(cop, 'serialize :foo') - - expect(cop.offenses).to be_empty - end - end -end diff --git a/spec/rubocop/cop/custom_error_class_spec.rb b/spec/rubocop/cop/custom_error_class_spec.rb deleted file mode 100644 index 381d7871a40..00000000000 --- a/spec/rubocop/cop/custom_error_class_spec.rb +++ /dev/null @@ -1,111 +0,0 @@ -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../rubocop/cop/custom_error_class' - -describe RuboCop::Cop::CustomErrorClass do - include CopHelper - - subject(:cop) { described_class.new } - - context 'when a class has a body' do - it 'does nothing' do - inspect_source(cop, 'class CustomError < StandardError; def foo; end; end') - - expect(cop.offenses).to be_empty - end - end - - context 'when a class has no explicit superclass' do - it 'does nothing' do - inspect_source(cop, 'class CustomError; end') - - expect(cop.offenses).to be_empty - end - end - - context 'when a class has a superclass that does not end in Error' do - it 'does nothing' do - inspect_source(cop, 'class CustomError < BasicObject; end') - - expect(cop.offenses).to be_empty - end - end - - context 'when a class is empty and inherits from a class ending in Error' do - context 'when the class is on a single line' do - let(:source) do - <<-SOURCE - module Foo - class CustomError < Bar::Baz::BaseError; end - end - SOURCE - end - - let(:expected) do - <<-EXPECTED - module Foo - CustomError = Class.new(Bar::Baz::BaseError) - end - EXPECTED - end - - it 'registers an offense' do - expected_highlights = source.split("\n")[1].strip - - inspect_source(cop, source) - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([2]) - expect(cop.highlights).to contain_exactly(expected_highlights) - end - end - - it 'autocorrects to the right version' do - autocorrected = autocorrect_source(cop, source, 'foo/custom_error.rb') - - expect(autocorrected).to eq(expected) - end - end - - context 'when the class is on multiple lines' do - let(:source) do - <<-SOURCE - module Foo - class CustomError < Bar::Baz::BaseError - end - end - SOURCE - end - - let(:expected) do - <<-EXPECTED - module Foo - CustomError = Class.new(Bar::Baz::BaseError) - end - EXPECTED - end - - it 'registers an offense' do - expected_highlights = source.split("\n")[1..2].join("\n").strip - - inspect_source(cop, source) - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([2]) - expect(cop.highlights).to contain_exactly(expected_highlights) - end - end - - it 'autocorrects to the right version' do - autocorrected = autocorrect_source(cop, source, 'foo/custom_error.rb') - - expect(autocorrected).to eq(expected) - end - end - end -end diff --git a/spec/rubocop/cop/gem_fetcher_spec.rb b/spec/rubocop/cop/gem_fetcher_spec.rb deleted file mode 100644 index c07f6a831dc..00000000000 --- a/spec/rubocop/cop/gem_fetcher_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../rubocop/cop/gem_fetcher' - -describe RuboCop::Cop::GemFetcher do - include CopHelper - - subject(:cop) { described_class.new } - - context 'in Gemfile' do - before do - allow(cop).to receive(:gemfile?).and_return(true) - end - - it 'registers an offense when a gem uses `git`' do - inspect_source(cop, 'gem "foo", git: "https://gitlab.com/foo/bar.git"') - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - expect(cop.highlights).to eq(['git: "https://gitlab.com/foo/bar.git"']) - end - end - - it 'registers an offense when a gem uses `github`' do - inspect_source(cop, 'gem "foo", github: "foo/bar.git"') - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - expect(cop.highlights).to eq(['github: "foo/bar.git"']) - end - end - end - - context 'outside of Gemfile' do - it 'registers no offense' do - inspect_source(cop, 'gem "foo", git: "https://gitlab.com/foo/bar.git"') - - expect(cop.offenses.size).to eq(0) - end - end -end diff --git a/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb b/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb index 1fd40653f79..8e2d5f70353 100644 --- a/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb +++ b/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb @@ -12,7 +12,7 @@ describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do let(:offending_lines) { options[:offending_lines] } it 'registers an offense when instance variable is used in a module' do - inspect_source(cop, source) + inspect_source(source) aggregate_failures do expect(cop.offenses.size).to eq(offending_lines.size) @@ -23,7 +23,7 @@ describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do shared_examples('not registering offense') do it 'does not register offenses' do - inspect_source(cop, source) + inspect_source(source) expect(cop.offenses).to be_empty end diff --git a/spec/rubocop/cop/in_batches_spec.rb b/spec/rubocop/cop/in_batches_spec.rb deleted file mode 100644 index 072481984c6..00000000000 --- a/spec/rubocop/cop/in_batches_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' -require 'rubocop' -require 'rubocop/rspec/support' -require_relative '../../../rubocop/cop/in_batches' - -describe RuboCop::Cop::InBatches do - include CopHelper - - subject(:cop) { described_class.new } - - it 'registers an offense when in_batches is used' do - inspect_source(cop, 'foo.in_batches do; end') - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - end - end -end diff --git a/spec/rubocop/cop/include_sidekiq_worker_spec.rb b/spec/rubocop/cop/include_sidekiq_worker_spec.rb index 7f406535dda..f5109287876 100644 --- a/spec/rubocop/cop/include_sidekiq_worker_spec.rb +++ b/spec/rubocop/cop/include_sidekiq_worker_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' + require 'rubocop' require 'rubocop/rspec/support' + require_relative '../../../rubocop/cop/include_sidekiq_worker' describe RuboCop::Cop::IncludeSidekiqWorker do @@ -13,7 +15,7 @@ describe RuboCop::Cop::IncludeSidekiqWorker do let(:correct_source) { 'include ApplicationWorker' } it 'registers an offense ' do - inspect_source(cop, source) + inspect_source(source) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -23,7 +25,7 @@ describe RuboCop::Cop::IncludeSidekiqWorker do end it 'autocorrects to the right version' do - autocorrected = autocorrect_source(cop, source) + autocorrected = autocorrect_source(source) expect(autocorrected).to eq(correct_source) end diff --git a/spec/rubocop/cop/line_break_after_guard_clauses_spec.rb b/spec/rubocop/cop/line_break_after_guard_clauses_spec.rb deleted file mode 100644 index 8899dc85384..00000000000 --- a/spec/rubocop/cop/line_break_after_guard_clauses_spec.rb +++ /dev/null @@ -1,160 +0,0 @@ -require 'spec_helper' -require 'rubocop' -require 'rubocop/rspec/support' -require_relative '../../../rubocop/cop/line_break_after_guard_clauses' - -describe RuboCop::Cop::LineBreakAfterGuardClauses do - include CopHelper - - subject(:cop) { described_class.new } - - shared_examples 'examples with guard clause' do |title| - %w[if unless].each do |conditional| - it "flags violation for #{title} #{conditional} without line breaks" do - source = <<~RUBY - #{title} #{conditional} condition - do_stuff - RUBY - inspect_source(cop, source) - - expect(cop.offenses.size).to eq(1) - offense = cop.offenses.first - - expect(offense.line).to eq(1) - expect(cop.highlights).to eq(["#{title} #{conditional} condition"]) - expect(offense.message).to eq('Add a line break after guard clauses') - end - - it "doesn't flag violation for #{title} #{conditional} with line break" do - source = <<~RUBY - #{title} #{conditional} condition - - do_stuff - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} #{conditional} on multiple lines without line break" do - source = <<~RUBY - #{conditional} condition - #{title} - end - do_stuff - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by end keyword" do - source = <<~RUBY - def test - #{title} #{conditional} condition - end - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by elsif keyword" do - source = <<~RUBY - if model - #{title} #{conditional} condition - elsif - do_something - end - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by else keyword" do - source = <<~RUBY - if model - #{title} #{conditional} condition - else - do_something - end - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by when keyword" do - source = <<~RUBY - case model - when condition_a - #{title} #{conditional} condition - when condition_b - do_something - end - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by rescue keyword" do - source = <<~RUBY - begin - #{title} #{conditional} condition - rescue StandardError - do_something - end - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by ensure keyword" do - source = <<~RUBY - def foo - #{title} #{conditional} condition - ensure - do_something - end - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} #{conditional} without line breaks when followed by another guard clause" do - source = <<~RUBY - #{title} #{conditional} condition - #{title} #{conditional} condition - - do_stuff - RUBY - inspect_source(cop, source) - - expect(cop.offenses).to be_empty - end - - it "autocorrects #{title} #{conditional} guard clauses without line break" do - source = <<~RUBY - #{title} #{conditional} condition - do_stuff - RUBY - autocorrected = autocorrect_source(cop, source) - - expected_source = <<~RUBY - #{title} #{conditional} condition - - do_stuff - RUBY - expect(autocorrected).to eql(expected_source) - end - end - end - - %w[return fail raise next break throw].each do |example| - it_behaves_like 'examples with guard clause', example - end -end diff --git a/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb b/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb index 7cb24dc5646..1df1fffb94e 100644 --- a/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb +++ b/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' + require 'rubocop' require 'rubocop/rspec/support' + require_relative '../../../../rubocop/cop/migration/add_concurrent_foreign_key' describe RuboCop::Cop::Migration::AddConcurrentForeignKey do @@ -10,7 +12,7 @@ describe RuboCop::Cop::Migration::AddConcurrentForeignKey do context 'outside of a migration' do it 'does not register any offenses' do - inspect_source(cop, 'def up; add_foreign_key(:projects, :users, column: :user_id); end') + inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end') expect(cop.offenses).to be_empty end @@ -22,7 +24,7 @@ describe RuboCop::Cop::Migration::AddConcurrentForeignKey do end it 'registers an offense when using add_foreign_key' do - inspect_source(cop, 'def up; add_foreign_key(:projects, :users, column: :user_id); end') + inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end') aggregate_failures do expect(cop.offenses.size).to eq(1) diff --git a/spec/rubocop/cop/migration/add_concurrent_index_spec.rb b/spec/rubocop/cop/migration/add_concurrent_index_spec.rb index 19a5718b0b1..9c1ebcc0ced 100644 --- a/spec/rubocop/cop/migration/add_concurrent_index_spec.rb +++ b/spec/rubocop/cop/migration/add_concurrent_index_spec.rb @@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do end it 'registers an offense when add_concurrent_index is used inside a change method' do - inspect_source(cop, 'def change; add_concurrent_index :table, :column; end') + inspect_source('def change; add_concurrent_index :table, :column; end') aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do end it 'registers no offense when add_concurrent_index is used inside an up method' do - inspect_source(cop, 'def up; add_concurrent_index :table, :column; end') + inspect_source('def up; add_concurrent_index :table, :column; end') expect(cop.offenses.size).to eq(0) end @@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::AddConcurrentIndex do context 'outside of migration' do it 'registers no offense' do - inspect_source(cop, 'def change; add_concurrent_index :table, :column; end') + inspect_source('def change; add_concurrent_index :table, :column; end') expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/add_timestamps_spec.rb b/spec/rubocop/cop/migration/add_timestamps_spec.rb index 18df62dec3e..3a41c91add2 100644 --- a/spec/rubocop/cop/migration/add_timestamps_spec.rb +++ b/spec/rubocop/cop/migration/add_timestamps_spec.rb @@ -53,7 +53,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do end it 'registers an offense when the "add_timestamps" method is used' do - inspect_source(cop, migration_with_add_timestamps) + inspect_source(migration_with_add_timestamps) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -62,7 +62,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do end it 'does not register an offense when the "add_timestamps" method is not used' do - inspect_source(cop, migration_without_add_timestamps) + inspect_source(migration_without_add_timestamps) aggregate_failures do expect(cop.offenses.size).to eq(0) @@ -70,7 +70,7 @@ describe RuboCop::Cop::Migration::AddTimestamps do end it 'does not register an offense when the "add_timestamps_with_timezone" method is used' do - inspect_source(cop, migration_with_add_timestamps_with_timezone) + inspect_source(migration_with_add_timestamps_with_timezone) aggregate_failures do expect(cop.offenses.size).to eq(0) @@ -80,9 +80,9 @@ describe RuboCop::Cop::Migration::AddTimestamps do context 'outside of migration' do it 'registers no offense' do - inspect_source(cop, migration_with_add_timestamps) - inspect_source(cop, migration_without_add_timestamps) - inspect_source(cop, migration_with_add_timestamps_with_timezone) + inspect_source(migration_with_add_timestamps) + inspect_source(migration_without_add_timestamps) + inspect_source(migration_with_add_timestamps_with_timezone) expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/datetime_spec.rb b/spec/rubocop/cop/migration/datetime_spec.rb index b1dfcf1b048..9e844325371 100644 --- a/spec/rubocop/cop/migration/datetime_spec.rb +++ b/spec/rubocop/cop/migration/datetime_spec.rb @@ -67,7 +67,7 @@ describe RuboCop::Cop::Migration::Datetime do end it 'registers an offense when the ":datetime" data type is used' do - inspect_source(cop, migration_with_datetime) + inspect_source(migration_with_datetime) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -77,7 +77,7 @@ describe RuboCop::Cop::Migration::Datetime do end it 'registers an offense when the ":timestamp" data type is used' do - inspect_source(cop, migration_with_timestamp) + inspect_source(migration_with_timestamp) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -87,7 +87,7 @@ describe RuboCop::Cop::Migration::Datetime do end it 'does not register an offense when the ":datetime" data type is not used' do - inspect_source(cop, migration_without_datetime) + inspect_source(migration_without_datetime) aggregate_failures do expect(cop.offenses.size).to eq(0) @@ -95,7 +95,7 @@ describe RuboCop::Cop::Migration::Datetime do end it 'does not register an offense when the ":datetime_with_timezone" data type is used' do - inspect_source(cop, migration_with_datetime_with_timezone) + inspect_source(migration_with_datetime_with_timezone) aggregate_failures do expect(cop.offenses.size).to eq(0) @@ -105,10 +105,10 @@ describe RuboCop::Cop::Migration::Datetime do context 'outside of migration' do it 'registers no offense' do - inspect_source(cop, migration_with_datetime) - inspect_source(cop, migration_with_timestamp) - inspect_source(cop, migration_without_datetime) - inspect_source(cop, migration_with_datetime_with_timezone) + inspect_source(migration_with_datetime) + inspect_source(migration_with_timestamp) + inspect_source(migration_without_datetime) + inspect_source(migration_with_datetime_with_timezone) expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/hash_index_spec.rb b/spec/rubocop/cop/migration/hash_index_spec.rb index 9a8576a19e5..5d53dde9a79 100644 --- a/spec/rubocop/cop/migration/hash_index_spec.rb +++ b/spec/rubocop/cop/migration/hash_index_spec.rb @@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::HashIndex do end it 'registers an offense when creating a hash index' do - inspect_source(cop, 'def change; add_index :table, :column, using: :hash; end') + inspect_source('def change; add_index :table, :column, using: :hash; end') aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::HashIndex do end it 'registers an offense when creating a concurrent hash index' do - inspect_source(cop, 'def change; add_concurrent_index :table, :column, using: :hash; end') + inspect_source('def change; add_concurrent_index :table, :column, using: :hash; end') aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -34,7 +34,7 @@ describe RuboCop::Cop::Migration::HashIndex do end it 'registers an offense when creating a hash index using t.index' do - inspect_source(cop, 'def change; t.index :table, :column, using: :hash; end') + inspect_source('def change; t.index :table, :column, using: :hash; end') aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -45,7 +45,7 @@ describe RuboCop::Cop::Migration::HashIndex do context 'outside of migration' do it 'registers no offense' do - inspect_source(cop, 'def change; index :table, :column, using: :hash; end') + inspect_source('def change; index :table, :column, using: :hash; end') expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/remove_column_spec.rb b/spec/rubocop/cop/migration/remove_column_spec.rb index 89112f01723..f1a64f431bd 100644 --- a/spec/rubocop/cop/migration/remove_column_spec.rb +++ b/spec/rubocop/cop/migration/remove_column_spec.rb @@ -21,7 +21,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do end it 'registers an offense when remove_column is used in the change method' do - inspect_source(cop, source('change')) + inspect_source(source('change')) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -30,7 +30,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do end it 'registers an offense when remove_column is used in the up method' do - inspect_source(cop, source('up')) + inspect_source(source('up')) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -39,7 +39,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do end it 'registers no offense when remove_column is used in the down method' do - inspect_source(cop, source('down')) + inspect_source(source('down')) expect(cop.offenses.size).to eq(0) end @@ -52,7 +52,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do end it 'registers no offense' do - inspect_source(cop, source) + inspect_source(source) expect(cop.offenses.size).to eq(0) end @@ -60,7 +60,7 @@ describe RuboCop::Cop::Migration::RemoveColumn do context 'outside of a migration' do it 'registers no offense' do - inspect_source(cop, source) + inspect_source(source) expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb b/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb index a714bf4e5d5..a23d5d022e3 100644 --- a/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb +++ b/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb @@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do end it 'registers an offense when remove_concurrent_index is used inside a change method' do - inspect_source(cop, 'def change; remove_concurrent_index :table, :column; end') + inspect_source('def change; remove_concurrent_index :table, :column; end') aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do end it 'registers no offense when remove_concurrent_index is used inside an up method' do - inspect_source(cop, 'def up; remove_concurrent_index :table, :column; end') + inspect_source('def up; remove_concurrent_index :table, :column; end') expect(cop.offenses.size).to eq(0) end @@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::RemoveConcurrentIndex do context 'outside of migration' do it 'registers no offense' do - inspect_source(cop, 'def change; remove_concurrent_index :table, :column; end') + inspect_source('def change; remove_concurrent_index :table, :column; end') expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/remove_index_spec.rb b/spec/rubocop/cop/migration/remove_index_spec.rb index 31923cb7429..bbf2227e512 100644 --- a/spec/rubocop/cop/migration/remove_index_spec.rb +++ b/spec/rubocop/cop/migration/remove_index_spec.rb @@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::RemoveIndex do end it 'registers an offense when remove_index is used' do - inspect_source(cop, 'def change; remove_index :table, :column; end') + inspect_source('def change; remove_index :table, :column; end') aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -27,7 +27,7 @@ describe RuboCop::Cop::Migration::RemoveIndex do context 'outside of migration' do it 'registers no offense' do - inspect_source(cop, 'def change; remove_index :table, :column; end') + inspect_source('def change; remove_index :table, :column; end') expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/reversible_add_column_with_default_spec.rb b/spec/rubocop/cop/migration/reversible_add_column_with_default_spec.rb index 3723d635083..ba8cd2c6c4a 100644 --- a/spec/rubocop/cop/migration/reversible_add_column_with_default_spec.rb +++ b/spec/rubocop/cop/migration/reversible_add_column_with_default_spec.rb @@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do end it 'registers an offense when add_column_with_default is used inside a change method' do - inspect_source(cop, 'def change; add_column_with_default :table, :column, default: false; end') + inspect_source('def change; add_column_with_default :table, :column, default: false; end') aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -25,7 +25,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do end it 'registers no offense when add_column_with_default is used inside an up method' do - inspect_source(cop, 'def up; add_column_with_default :table, :column, default: false; end') + inspect_source('def up; add_column_with_default :table, :column, default: false; end') expect(cop.offenses.size).to eq(0) end @@ -33,7 +33,7 @@ describe RuboCop::Cop::Migration::ReversibleAddColumnWithDefault do context 'outside of migration' do it 'registers no offense' do - inspect_source(cop, 'def change; add_column_with_default :table, :column, default: false; end') + inspect_source('def change; add_column_with_default :table, :column, default: false; end') expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/safer_boolean_column_spec.rb b/spec/rubocop/cop/migration/safer_boolean_column_spec.rb index 1006594499a..1c4f18fbcc3 100644 --- a/spec/rubocop/cop/migration/safer_boolean_column_spec.rb +++ b/spec/rubocop/cop/migration/safer_boolean_column_spec.rb @@ -32,7 +32,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do sources_and_offense.each do |source, offense| context "given the source \"#{source}\"" do it "registers the offense matching \"#{offense}\"" do - inspect_source(cop, source) + inspect_source(source) aggregate_failures do expect(cop.offenses.first.message).to match(offense) @@ -49,7 +49,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do inoffensive_sources.each do |source| context "given the source \"#{source}\"" do it "registers no offense" do - inspect_source(cop, source) + inspect_source(source) aggregate_failures do expect(cop.offenses).to be_empty @@ -61,14 +61,14 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do end it 'registers no offense for tables not listed in SMALL_TABLES' do - inspect_source(cop, "add_column :large_table, :column, :boolean") + inspect_source("add_column :large_table, :column, :boolean") expect(cop.offenses).to be_empty end it 'registers no offense for non-boolean columns' do table = described_class::SMALL_TABLES.sample - inspect_source(cop, "add_column :#{table}, :column, :string") + inspect_source("add_column :#{table}, :column, :string") expect(cop.offenses).to be_empty end @@ -77,7 +77,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do context 'outside of migration' do it 'registers no offense' do table = described_class::SMALL_TABLES.sample - inspect_source(cop, "add_column :#{table}, :column, :boolean") + inspect_source("add_column :#{table}, :column, :boolean") expect(cop.offenses).to be_empty end diff --git a/spec/rubocop/cop/migration/timestamps_spec.rb b/spec/rubocop/cop/migration/timestamps_spec.rb index cdf1423d0c5..685bdb21803 100644 --- a/spec/rubocop/cop/migration/timestamps_spec.rb +++ b/spec/rubocop/cop/migration/timestamps_spec.rb @@ -62,7 +62,7 @@ describe RuboCop::Cop::Migration::Timestamps do end it 'registers an offense when the "timestamps" method is used' do - inspect_source(cop, migration_with_timestamps) + inspect_source(migration_with_timestamps) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -71,7 +71,7 @@ describe RuboCop::Cop::Migration::Timestamps do end it 'does not register an offense when the "timestamps" method is not used' do - inspect_source(cop, migration_without_timestamps) + inspect_source(migration_without_timestamps) aggregate_failures do expect(cop.offenses.size).to eq(0) @@ -79,7 +79,7 @@ describe RuboCop::Cop::Migration::Timestamps do end it 'does not register an offense when the "timestamps_with_timezone" method is used' do - inspect_source(cop, migration_with_timestamps_with_timezone) + inspect_source(migration_with_timestamps_with_timezone) aggregate_failures do expect(cop.offenses.size).to eq(0) @@ -89,9 +89,9 @@ describe RuboCop::Cop::Migration::Timestamps do context 'outside of migration' do it 'registers no offense' do - inspect_source(cop, migration_with_timestamps) - inspect_source(cop, migration_without_timestamps) - inspect_source(cop, migration_with_timestamps_with_timezone) + inspect_source(migration_with_timestamps) + inspect_source(migration_without_timestamps) + inspect_source(migration_with_timestamps_with_timezone) expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/migration/update_column_in_batches_spec.rb b/spec/rubocop/cop/migration/update_column_in_batches_spec.rb index 38b8f439a55..1c8ab0ad5d2 100644 --- a/spec/rubocop/cop/migration/update_column_in_batches_spec.rb +++ b/spec/rubocop/cop/migration/update_column_in_batches_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' + require 'rubocop' require 'rubocop/rspec/support' + require_relative '../../../../rubocop/cop/migration/update_column_in_batches' describe RuboCop::Cop::Migration::UpdateColumnInBatches do @@ -25,7 +27,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do context 'outside of a migration' do it 'does not register any offenses' do - inspect_source(cop, migration_code) + inspect_source(migration_code) expect(cop.offenses).to be_empty end @@ -49,7 +51,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do let(:relative_spec_filepath) { Pathname.new(spec_filepath).relative_path_from(tmp_rails_root) } it 'registers an offense when using update_column_in_batches' do - inspect_source(cop, migration_code, @migration_file) + inspect_source(migration_code, @migration_file) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -72,7 +74,7 @@ describe RuboCop::Cop::Migration::UpdateColumnInBatches do end it 'does not register any offenses' do - inspect_source(cop, migration_code, @migration_file) + inspect_source(migration_code, @migration_file) expect(cop.offenses).to be_empty end diff --git a/spec/rubocop/cop/migration/update_large_table_spec.rb b/spec/rubocop/cop/migration/update_large_table_spec.rb index 17b19e139e4..ef724fc8bad 100644 --- a/spec/rubocop/cop/migration/update_large_table_spec.rb +++ b/spec/rubocop/cop/migration/update_large_table_spec.rb @@ -18,7 +18,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do shared_examples 'large tables' do |update_method| described_class::LARGE_TABLES.each do |table| it "registers an offense for the #{table} table" do - inspect_source(cop, "#{update_method} :#{table}, :column, default: true") + inspect_source("#{update_method} :#{table}, :column, default: true") aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -37,7 +37,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do end it 'registers no offense for non-blacklisted tables' do - inspect_source(cop, "add_column_with_default :table, :column, default: true") + inspect_source("add_column_with_default :table, :column, default: true") expect(cop.offenses).to be_empty end @@ -45,7 +45,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do it 'registers no offense for non-blacklisted methods' do table = described_class::LARGE_TABLES.sample - inspect_source(cop, "some_other_method :#{table}, :column, default: true") + inspect_source("some_other_method :#{table}, :column, default: true") expect(cop.offenses).to be_empty end @@ -55,13 +55,13 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do let(:table) { described_class::LARGE_TABLES.sample } it 'registers no offense for add_column_with_default' do - inspect_source(cop, "add_column_with_default :#{table}, :column, default: true") + inspect_source("add_column_with_default :#{table}, :column, default: true") expect(cop.offenses).to be_empty end it 'registers no offense for update_column_in_batches' do - inspect_source(cop, "add_column_with_default :#{table}, :column, default: true") + inspect_source("add_column_with_default :#{table}, :column, default: true") expect(cop.offenses).to be_empty end diff --git a/spec/rubocop/cop/polymorphic_associations_spec.rb b/spec/rubocop/cop/polymorphic_associations_spec.rb deleted file mode 100644 index 49959aa6419..00000000000 --- a/spec/rubocop/cop/polymorphic_associations_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'spec_helper' -require 'rubocop' -require 'rubocop/rspec/support' -require_relative '../../../rubocop/cop/polymorphic_associations' - -describe RuboCop::Cop::PolymorphicAssociations do - include CopHelper - - subject(:cop) { described_class.new } - - context 'inside the app/models directory' do - it 'registers an offense when polymorphic: true is used' do - allow(cop).to receive(:in_model?).and_return(true) - - inspect_source(cop, 'belongs_to :foo, polymorphic: true') - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - end - end - end - - context 'outside the app/models directory' do - it 'does nothing' do - allow(cop).to receive(:in_model?).and_return(false) - - inspect_source(cop, 'belongs_to :foo, polymorphic: true') - - expect(cop.offenses).to be_empty - end - end -end diff --git a/spec/rubocop/cop/project_path_helper_spec.rb b/spec/rubocop/cop/project_path_helper_spec.rb index bc47b45cad7..84e6eb7d87f 100644 --- a/spec/rubocop/cop/project_path_helper_spec.rb +++ b/spec/rubocop/cop/project_path_helper_spec.rb @@ -15,7 +15,7 @@ describe RuboCop::Cop::ProjectPathHelper do let(:correct_source) { 'edit_project_issue_path(@issue.project, @issue)' } it 'registers an offense' do - inspect_source(cop, source) + inspect_source(source) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -25,7 +25,7 @@ describe RuboCop::Cop::ProjectPathHelper do end it 'autocorrects to the right version' do - autocorrected = autocorrect_source(cop, source) + autocorrected = autocorrect_source(source) expect(autocorrected).to eq(correct_source) end @@ -33,7 +33,7 @@ describe RuboCop::Cop::ProjectPathHelper do context 'when using namespace_project with a different namespace' do it 'registers no offense' do - inspect_source(cop, 'edit_namespace_project_issue_path(namespace, project)') + inspect_source('edit_namespace_project_issue_path(namespace, project)') expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/redirect_with_status_spec.rb b/spec/rubocop/cop/redirect_with_status_spec.rb deleted file mode 100644 index 5ad63567f84..00000000000 --- a/spec/rubocop/cop/redirect_with_status_spec.rb +++ /dev/null @@ -1,86 +0,0 @@ -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../rubocop/cop/redirect_with_status' - -describe RuboCop::Cop::RedirectWithStatus do - include CopHelper - - subject(:cop) { described_class.new } - let(:controller_fixture_without_status) do - %q( - class UserController < ApplicationController - def show - user = User.find(params[:id]) - redirect_to user_path if user.name == 'John Wick' - end - - def destroy - user = User.find(params[:id]) - - if user.destroy - redirect_to root_path - else - render :show - end - end - end - ) - end - - let(:controller_fixture_with_status) do - %q( - class UserController < ApplicationController - def show - user = User.find(params[:id]) - redirect_to user_path if user.name == 'John Wick' - end - - def destroy - user = User.find(params[:id]) - - if user.destroy - redirect_to root_path, status: 302 - else - render :show - end - end - end - ) - end - - context 'in controller' do - before do - allow(cop).to receive(:in_controller?).and_return(true) - end - - it 'registers an offense when a "destroy" action uses "redirect_to" without "status"' do - inspect_source(cop, controller_fixture_without_status) - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([12]) # 'redirect_to' is located on 12th line in controller_fixture. - expect(cop.highlights).to eq(['redirect_to']) - end - end - - it 'does not register an offense when a "destroy" action uses "redirect_to" with "status"' do - inspect_source(cop, controller_fixture_with_status) - - aggregate_failures do - expect(cop.offenses.size).to eq(0) - end - end - end - - context 'outside of controller' do - it 'registers no offense' do - inspect_source(cop, controller_fixture_without_status) - inspect_source(cop, controller_fixture_with_status) - - expect(cop.offenses.size).to eq(0) - end - end -end diff --git a/spec/rubocop/cop/rspec/env_assignment_spec.rb b/spec/rubocop/cop/rspec/env_assignment_spec.rb index 4e859b6f6fa..659633f6467 100644 --- a/spec/rubocop/cop/rspec/env_assignment_spec.rb +++ b/spec/rubocop/cop/rspec/env_assignment_spec.rb @@ -17,7 +17,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do shared_examples 'an offensive ENV#[]= call' do |content| it "registers an offense for `#{content}`" do - inspect_source(cop, content, source_file) + inspect_source(content, source_file) expect(cop.offenses.size).to eq(1) expect(cop.offenses.map(&:line)).to eq([1]) @@ -27,7 +27,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do 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(cop, content, source_file) + autocorrected = autocorrect_source(content, source_file) expect(autocorrected).to eql(autocorrected_content) end @@ -51,7 +51,7 @@ describe RuboCop::Cop::RSpec::EnvAssignment do context 'outside of a spec file' do it "does not register an offense for `#{OFFENSE_CALL_SINGLE_QUOTES_KEY}` in a non-spec file" do - inspect_source(cop, OFFENSE_CALL_SINGLE_QUOTES_KEY) + inspect_source(OFFENSE_CALL_SINGLE_QUOTES_KEY) expect(cop.offenses.size).to eq(0) end diff --git a/spec/rubocop/cop/rspec/single_line_hook_spec.rb b/spec/rubocop/cop/rspec/single_line_hook_spec.rb deleted file mode 100644 index 6cf0831d3ad..00000000000 --- a/spec/rubocop/cop/rspec/single_line_hook_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../../rubocop/cop/rspec/single_line_hook' - -describe RuboCop::Cop::RSpec::SingleLineHook do - include CopHelper - - subject(:cop) { described_class.new } - - # Override `CopHelper#inspect_source` to always appear to be in a spec file, - # so that our RSpec-only cop actually runs - def inspect_source(*args) - super(*args, 'foo_spec.rb') - end - - it 'registers an offense for a single-line `before` block' do - inspect_source(cop, 'before { do_something }') - - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - expect(cop.highlights).to eq(['before { do_something }']) - end - - it 'registers an offense for a single-line `after` block' do - inspect_source(cop, 'after(:each) { undo_something }') - - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - expect(cop.highlights).to eq(['after(:each) { undo_something }']) - end - - it 'registers an offense for a single-line `around` block' do - inspect_source(cop, 'around { |ex| do_something_else }') - - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - expect(cop.highlights).to eq(['around { |ex| do_something_else }']) - end - - it 'ignores a multi-line `before` block' do - inspect_source(cop, ['before do', - ' do_something', - 'end']) - - expect(cop.offenses.size).to eq(0) - end - - it 'ignores a multi-line `after` block' do - inspect_source(cop, ['after(:each) do', - ' undo_something', - 'end']) - - expect(cop.offenses.size).to eq(0) - end - - it 'ignores a multi-line `around` block' do - inspect_source(cop, ['around do |ex|', - ' do_something_else', - 'end']) - - expect(cop.offenses.size).to eq(0) - end -end diff --git a/spec/rubocop/cop/rspec/verbose_include_metadata_spec.rb b/spec/rubocop/cop/rspec/verbose_include_metadata_spec.rb deleted file mode 100644 index 278662d32ea..00000000000 --- a/spec/rubocop/cop/rspec/verbose_include_metadata_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper' -require 'rubocop' -require 'rubocop/rspec/support' -require_relative '../../../../rubocop/cop/rspec/verbose_include_metadata' - -describe RuboCop::Cop::RSpec::VerboseIncludeMetadata do - include CopHelper - - subject(:cop) { described_class.new } - - let(:source_file) { 'foo_spec.rb' } - - # Override `CopHelper#inspect_source` to always appear to be in a spec file, - # so that our RSpec-only cop actually runs - def inspect_source(*args) - super(*args, source_file) - end - - shared_examples 'examples with include syntax' do |title| - it "flags violation for #{title} examples that uses verbose include syntax" do - inspect_source(cop, "#{title} 'Test', js: true do; end") - - expect(cop.offenses.size).to eq(1) - offense = cop.offenses.first - - expect(offense.line).to eq(1) - expect(cop.highlights).to eq(["#{title} 'Test', js: true"]) - expect(offense.message).to eq('Use `:js` instead of `js: true`.') - end - - it "doesn't flag violation for #{title} examples that uses compact include syntax", :aggregate_failures do - inspect_source(cop, "#{title} 'Test', :js do; end") - - expect(cop.offenses).to be_empty - end - - it "doesn't flag violation for #{title} examples that uses flag: symbol" do - inspect_source(cop, "#{title} 'Test', flag: :symbol do; end") - - expect(cop.offenses).to be_empty - end - - it "autocorrects #{title} examples that uses verbose syntax into compact syntax" do - autocorrected = autocorrect_source(cop, "#{title} 'Test', js: true do; end", source_file) - - expect(autocorrected).to eql("#{title} 'Test', :js do; end") - end - end - - %w(describe context feature example_group it specify example scenario its).each do |example| - it_behaves_like 'examples with include syntax', example - end -end diff --git a/spec/rubocop/cop/sidekiq_options_queue_spec.rb b/spec/rubocop/cop/sidekiq_options_queue_spec.rb index a31de381631..7f237d5ffbb 100644 --- a/spec/rubocop/cop/sidekiq_options_queue_spec.rb +++ b/spec/rubocop/cop/sidekiq_options_queue_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' + require 'rubocop' require 'rubocop/rspec/support' + require_relative '../../../rubocop/cop/sidekiq_options_queue' describe RuboCop::Cop::SidekiqOptionsQueue do @@ -9,7 +11,7 @@ describe RuboCop::Cop::SidekiqOptionsQueue do subject(:cop) { described_class.new } it 'registers an offense when `sidekiq_options` is used with the `queue` option' do - inspect_source(cop, 'sidekiq_options queue: "some_queue"') + inspect_source('sidekiq_options queue: "some_queue"') aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -19,7 +21,7 @@ describe RuboCop::Cop::SidekiqOptionsQueue do end it 'does not register an offense when `sidekiq_options` is used with another option' do - inspect_source(cop, 'sidekiq_options retry: false') + inspect_source('sidekiq_options retry: false') expect(cop.offenses).to be_empty end |