From ef72e9ab3b9e05070d5a66ab06eccdd228003a3b Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Thu, 13 Feb 2020 00:38:34 +0900 Subject: [PATCH] Update testing context for Rails versions This PR updates testing context for Rails versions. With this change testing context can be specified by minor version. --- .../rubocop/cop/rails/application_job_spec.rb | 4 ++-- .../cop/rails/application_mailer_spec.rb | 4 ++-- .../cop/rails/application_record_spec.rb | 4 ++-- .../cop/rails/bulk_change_table_spec.rb | 16 ++++--------- .../rails/http_positional_arguments_spec.rb | 4 ++-- spec/rubocop/cop/rails/inverse_of_spec.rb | 10 +++----- ...redundant_receiver_in_with_options_spec.rb | 8 ++----- spec/support/shared_contexts.rb | 24 +++++++++++++++++-- 8 files changed, 39 insertions(+), 35 deletions(-) diff --git a/spec/rubocop/cop/rails/application_job_spec.rb b/spec/rubocop/cop/rails/application_job_spec.rb index 5b2fab19af..cc50ea21f6 100644 --- a/spec/rubocop/cop/rails/application_job_spec.rb +++ b/spec/rubocop/cop/rails/application_job_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::Rails::ApplicationJob do - context 'rails 4', :rails4, :config do + context 'Rails 4.2', :rails42, :config do subject(:cop) { described_class.new(config) } it 'allows ApplicationJob to be defined' do @@ -55,7 +55,7 @@ class Nested::MyJob < ActiveJob::Base end end - context 'rails 5', :rails5 do + context 'Rails 5.0', :rails50 do subject(:cop) { described_class.new } it 'allows `ApplicationJob` to be defined' do diff --git a/spec/rubocop/cop/rails/application_mailer_spec.rb b/spec/rubocop/cop/rails/application_mailer_spec.rb index a5c98b401a..d57afadb81 100644 --- a/spec/rubocop/cop/rails/application_mailer_spec.rb +++ b/spec/rubocop/cop/rails/application_mailer_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::Rails::ApplicationMailer do - context 'rails 4', :rails4, :config do + context 'Rails 4.2', :rails42, :config do subject(:cop) { described_class.new(config) } it 'allows `ApplicationMailer` to be defined' do @@ -55,7 +55,7 @@ class Nested::MyMailer < ActionMailer::Base; end end end - context 'rails 5', :rails5 do + context 'Rails 5.0', :rails50 do subject(:cop) { described_class.new } it 'allows `ApplicationMailer` to be defined' do diff --git a/spec/rubocop/cop/rails/application_record_spec.rb b/spec/rubocop/cop/rails/application_record_spec.rb index 07b3710ef8..5b55d0f081 100644 --- a/spec/rubocop/cop/rails/application_record_spec.rb +++ b/spec/rubocop/cop/rails/application_record_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::Rails::ApplicationRecord do - context 'rails 4', :rails4, :config do + context 'Rails 4.2', :rails42, :config do subject(:cop) { described_class.new(config) } it 'allows ApplicationRecord to be defined' do @@ -51,7 +51,7 @@ class Nested::MyModel < ActiveRecord::Base; end end end - context 'rails 5', :rails5 do + context 'Rails 5.0', :rails50 do subject(:cop) { described_class.new } it 'allows ApplicationRecord to be defined' do diff --git a/spec/rubocop/cop/rails/bulk_change_table_spec.rb b/spec/rubocop/cop/rails/bulk_change_table_spec.rb index 3dfa78f75b..e963ccbab8 100644 --- a/spec/rubocop/cop/rails/bulk_change_table_spec.rb +++ b/spec/rubocop/cop/rails/bulk_change_table_spec.rb @@ -399,17 +399,13 @@ def change } end - context 'with Rails 5.2' do - let(:rails_version) { 5.2 } - + context 'with Rails 5.2', :rails52 do it_behaves_like 'offense' it_behaves_like 'no offense for mysql' it_behaves_like 'offense for postgresql' end - context 'with Rails 5.1' do - let(:rails_version) { 5.1 } - + context 'with Rails 5.1', :rails51 do it_behaves_like 'no offense' it_behaves_like 'no offense for mysql' it_behaves_like 'no offense for postgresql' @@ -449,15 +445,11 @@ def change } end - context 'with Rails 5.2' do - let(:rails_version) { 5.2 } - + context 'with Rails 5.2', :rails52 do it_behaves_like 'offense for postgresql' end - context 'with Rails 5.1' do - let(:rails_version) { 5.1 } - + context 'with Rails 5.1', :rails51 do it_behaves_like 'no offense for postgresql' end end diff --git a/spec/rubocop/cop/rails/http_positional_arguments_spec.rb b/spec/rubocop/cop/rails/http_positional_arguments_spec.rb index 5fe78b7bcd..e9383d5a30 100644 --- a/spec/rubocop/cop/rails/http_positional_arguments_spec.rb +++ b/spec/rubocop/cop/rails/http_positional_arguments_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::Rails::HttpPositionalArguments do - context 'rails 4', :rails4, :config do + context 'Rails 4.2', :rails42, :config do subject(:cop) { described_class.new(config) } it 'does not register an offense for get method' do @@ -99,7 +99,7 @@ end end - context 'rails 5 and above', :rails5 do + context 'Rails 5.0 and above', :rails50 do subject(:cop) { described_class.new } it 'registers an offense for get method' do diff --git a/spec/rubocop/cop/rails/inverse_of_spec.rb b/spec/rubocop/cop/rails/inverse_of_spec.rb index 0a2cccaca8..257cc9742b 100644 --- a/spec/rubocop/cop/rails/inverse_of_spec.rb +++ b/spec/rubocop/cop/rails/inverse_of_spec.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true -RSpec.describe RuboCop::Cop::Rails::InverseOf do +RSpec.describe RuboCop::Cop::Rails::InverseOf, :config do subject(:cop) { described_class.new(config) } - let(:config) { RuboCop::Config.new } - context 'with scope' do it 'registers an offense when not specifying `:inverse_of`' do expect_offense(<<~RUBY) @@ -90,7 +88,7 @@ class Person end context '`:as` option' do - context 'Rails < 5.2', :rails5 do + context 'Rails <= 5.1', :rails51 do it 'registers an offense when not specifying `:inverse_of`' do expect_offense(<<~RUBY) class Person @@ -101,9 +99,7 @@ class Person end end - context 'Rails >= 5.2', :config do - let(:rails_version) { 5.2 } - + context 'Rails >= 5.2', :rails52 do it 'does not register an offense when not specifying `:inverse_of`' do expect_no_offenses( 'has_many :pictures, as: :imageable' diff --git a/spec/rubocop/cop/rails/redundant_receiver_in_with_options_spec.rb b/spec/rubocop/cop/rails/redundant_receiver_in_with_options_spec.rb index 492bfdb0df..19e34f1b10 100644 --- a/spec/rubocop/cop/rails/redundant_receiver_in_with_options_spec.rb +++ b/spec/rubocop/cop/rails/redundant_receiver_in_with_options_spec.rb @@ -3,9 +3,7 @@ RSpec.describe RuboCop::Cop::Rails::RedundantReceiverInWithOptions, :config do subject(:cop) { described_class.new(config) } - context 'rails >= 4.2' do - let(:rails_version) { 4.2 } - + context 'Rails >= 4.2', :rails42 do it 'registers an offense and corrects using explicit receiver ' \ 'in `with_options`' do expect_offense(<<~RUBY) @@ -96,9 +94,7 @@ class Account < ApplicationRecord end end - context 'rails <= 4.1' do - let(:rails_version) { 4.1 } - + context 'Rails <= 4.1', :rails41 do it 'does not register an offense when using explicit receiver in ' \ '`with_options`' do expect_no_offenses(<<~RUBY) diff --git a/spec/support/shared_contexts.rb b/spec/support/shared_contexts.rb index 963b588a1d..ebb393595d 100644 --- a/spec/support/shared_contexts.rb +++ b/spec/support/shared_contexts.rb @@ -1,9 +1,29 @@ # frozen_string_literal: true -RSpec.shared_context 'with Rails 4', :rails4 do +RSpec.shared_context 'with Rails 4.0', :rails40 do let(:rails_version) { 4.0 } end -RSpec.shared_context 'with Rails 5', :rails5 do +RSpec.shared_context 'with Rails 4.1', :rails41 do + let(:rails_version) { 4.1 } +end + +RSpec.shared_context 'with Rails 4.2', :rails42 do + let(:rails_version) { 4.2 } +end + +RSpec.shared_context 'with Rails 5.0', :rails50 do let(:rails_version) { 5.0 } end + +RSpec.shared_context 'with Rails 5.1', :rails51 do + let(:rails_version) { 5.1 } +end + +RSpec.shared_context 'with Rails 5.2', :rails52 do + let(:rails_version) { 5.2 } +end + +RSpec.shared_context 'with Rails 6.0', :rails60 do + let(:rails_version) { 6.0 } +end