Skip to content

Commit

Permalink
Merge pull request #198 from koic/update_testing_context
Browse files Browse the repository at this point in the history
Update testing context for Rails versions
  • Loading branch information
koic authored Feb 13, 2020
2 parents df17069 + ef72e9a commit 06bd9df
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rails/application_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rails/application_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rails/application_record_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions spec/rubocop/cop/rails/bulk_change_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rails/http_positional_arguments_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions spec/rubocop/cop/rails/inverse_of_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 22 additions & 2 deletions spec/support/shared_contexts.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 06bd9df

Please sign in to comment.