Skip to content

Commit

Permalink
DEV: Enable some cops related to RSpec subject
Browse files Browse the repository at this point in the history
This patch enables these cops:

- `RSpec/LeadingSubject`
- `RSpec/EmptyLineAfterSubject`
- `RSpec/NamedSubject`
  • Loading branch information
Flink committed Jun 26, 2023
1 parent 6c2bc57 commit 4a86e0b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion rubocop-discourse.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = "rubocop-discourse"
s.version = "3.2.0"
s.version = "3.3.0"
s.summary = "Custom rubocop cops used by Discourse"
s.authors = ["Discourse Team"]
s.license = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions rubocop-rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ RSpec/EmptyLineAfterHook:
Enabled: false # TODO

RSpec/EmptyLineAfterSubject:
Enabled: false # TODO
Enabled: true

RSpec/ExampleLength:
Enabled: false # To be decided
Expand Down Expand Up @@ -130,7 +130,7 @@ RSpec/IteratedExpectation:
Enabled: false # To be decided

RSpec/LeadingSubject:
Enabled: false # TODO
Enabled: true

RSpec/LeakyConstantDeclaration:
Enabled: false # To be decided
Expand All @@ -157,7 +157,7 @@ RSpec/MultipleSubjects:
Enabled: true

RSpec/NamedSubject:
Enabled: false # To be decided
Enabled: true

RSpec/NestedGroups:
Enabled: false # To be decided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
:config do
subject(:cop) { described_class.new(config) }

let(:config) { RuboCop::Config.new }

it "raises an offense if add_reference is used, with or without arguments" do
inspect_source(<<~RUBY)
add_reference :posts, :users, foreign_key: true, null: false
RUBY
expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "raises an offense if add_belongs_to is used, with or without arguments" do
inspect_source(<<~RUBY)
add_belongs_to :posts, :users, foreign_key: true, null: false
RUBY
expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "raises an offense if t.references, or any variable.references is used, with or without arguments" do
Expand All @@ -31,7 +32,7 @@
end
RUBY
expect(cop.offenses.count).to eq(2)
expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "raises an offense if t.belongs_to, or any variable.belongs_to is used, with or without arguments" do
Expand All @@ -44,6 +45,6 @@
end
RUBY
expect(cop.offenses.count).to eq(2)
expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "raises an offense if there are multiple multisite and standard top-level describes" do
Expand All @@ -31,7 +31,7 @@
end
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "does not raise an offense if there are only multisite describes" do
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/rubocop/cop/no_mocking_jobs_enqueue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
Jobs.expects(:enqueue)
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to end_with(described_class::MSG)
end

it "raises an offense if Jobs is mocked with :enqueue_in" do
inspect_source(<<~RUBY)
Jobs.expects(:enqueue_in)
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to end_with(described_class::MSG)
end

it "does not raise an offense if Jobs is not mocked with :enqueue or :enqueue_in" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

let(:config) { RuboCop::Config.new }

before { config["Discourse/NoResetColumnInformationInMigrations"]["Enabled"] = true }

it "raises an offense if reset_column_information is used" do
inspect_source(<<~RUBY)
class SomeMigration < ActiveRecord::Migration[6.0]
Expand All @@ -17,7 +19,7 @@ def up
end
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "raise an offense if reset_column_information is used without AR model" do
Expand All @@ -29,6 +31,6 @@ def up
end
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end
end
8 changes: 4 additions & 4 deletions spec/lib/rubocop/cop/only_top_level_multisite_specs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "raises an offense if multisite config option is used in a sub-describe (RSpec const version)" do
Expand All @@ -26,7 +26,7 @@
end
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "raises an offense if multisite config option is used in an example" do
Expand All @@ -40,7 +40,7 @@
end
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "raises an offense if multisite config option is used in a context" do
Expand All @@ -51,7 +51,7 @@
end
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "does not raise an offense if multisite config option is used on top-level describe" do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/rubocop/cop/time_eq_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
expect(user.created_at).to eq(Time.zone.now)
RUBY

expect(cop.offenses.first.message).to eq(described_class::MSG)
expect(cop.offenses.first.message).to match(described_class::MSG)
end

it "passes if a timestamp is compared using `eq_time`" do
Expand Down

0 comments on commit 4a86e0b

Please sign in to comment.