rubocop-discourse 3.13.3 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -3
  3. data/lib/rubocop/cop/discourse/plugins/call_requires_plugin.rb +1 -2
  4. data/lib/rubocop/cop/discourse/plugins/no_monkey_patching.rb +5 -12
  5. data/lib/rubocop/cop/discourse/plugins/use_plugin_instance_on.rb +1 -2
  6. data/lib/rubocop/cop/discourse/services/empty_lines_around_blocks.rb +6 -12
  7. data/lib/rubocop/cop/discourse/services/group_keywords.rb +2 -7
  8. data/lib/rubocop/discourse/version.rb +1 -1
  9. data/rubocop-core.yml +2 -143
  10. data/rubocop-discourse.gemspec +15 -2
  11. data/rubocop-layout.yml +2 -80
  12. data/rubocop-rspec.yml +9 -215
  13. metadata +5 -35
  14. data/.github/workflows/ci.yml +0 -41
  15. data/.gitignore +0 -1
  16. data/.rspec +0 -1
  17. data/.rubocop.yml +0 -9
  18. data/.streerc +0 -2
  19. data/Gemfile +0 -11
  20. data/Rakefile +0 -8
  21. data/spec/fixtures/controllers/bad_controller.rb +0 -5
  22. data/spec/fixtures/controllers/base_controller.rb +0 -11
  23. data/spec/fixtures/controllers/good_controller.rb +0 -4
  24. data/spec/fixtures/controllers/inherit_from_outside_controller.rb +0 -5
  25. data/spec/fixtures/controllers/namespaced_parent_controller.rb +0 -5
  26. data/spec/fixtures/controllers/no_requires_plugin_controller.rb +0 -5
  27. data/spec/fixtures/controllers/requires_plugin_controller.rb +0 -6
  28. data/spec/lib/rubocop/cop/discourse/services/empty_lines_around_blocks_spec.rb +0 -309
  29. data/spec/lib/rubocop/cop/discourse/services/group_keywords_spec.rb +0 -137
  30. data/spec/lib/rubocop/cop/fabricator_shorthand_spec.rb +0 -71
  31. data/spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb +0 -47
  32. data/spec/lib/rubocop/cop/no_mixing_multisite_and_standard_specs_spec.rb +0 -68
  33. data/spec/lib/rubocop/cop/no_mocking_jobs_enqueue_spec.rb +0 -31
  34. data/spec/lib/rubocop/cop/no_reset_column_information_migrations_spec.rb +0 -33
  35. data/spec/lib/rubocop/cop/only_top_level_multisite_specs_spec.rb +0 -78
  36. data/spec/lib/rubocop/cop/plugins/call_requires_plugin_spec.rb +0 -79
  37. data/spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb +0 -40
  38. data/spec/lib/rubocop/cop/plugins/namespace_methods_spec.rb +0 -84
  39. data/spec/lib/rubocop/cop/plugins/no_monkey_patching_spec.rb +0 -91
  40. data/spec/lib/rubocop/cop/plugins/use_plugin_instance_on_spec.rb +0 -37
  41. data/spec/lib/rubocop/cop/plugins/use_require_relative_spec.rb +0 -24
  42. data/spec/lib/rubocop/cop/time_eq_matcher_spec.rb +0 -23
  43. data/spec/spec_helper.rb +0 -15
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::FabricatorShorthand, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- it "registers an offense when not using the fabricator shorthand" do
9
- expect_offense(<<~RUBY)
10
- RSpec.describe "Foo" do
11
- fab!(:foo) { Fabricate(:foo) }
12
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:foo)`
13
- end
14
- RUBY
15
- end
16
-
17
- it "does not register an offense when the fabricator has attributes" do
18
- expect_no_offenses(<<~RUBY)
19
- RSpec.describe "Foo" do
20
- fab!(:foo) { Fabricate(:foo, bar: 1) }
21
- end
22
- RUBY
23
- end
24
-
25
- it "registers an offense when the identifier doesn't match and can be simplified" do
26
- expect_offense(<<~RUBY)
27
- RSpec.describe "Foo" do
28
- fab!(:bar) { Fabricate(:foo) }
29
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:bar, :foo)`
30
- end
31
- RUBY
32
- end
33
-
34
- it "does not register an offense when the identifier doesn't match and the fabricator has attributes" do
35
- expect_no_offenses(<<~RUBY)
36
- RSpec.describe "Foo" do
37
- fab!(:bar) { Fabricate(:foo, bar: 1) }
38
- end
39
- RUBY
40
- end
41
-
42
- it "supports autocorrect when the name and fabricator matches" do
43
- expect_offense(<<~RUBY)
44
- RSpec.describe "Foo" do
45
- fab!(:foo) { Fabricate(:foo) }
46
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:foo)`
47
- end
48
- RUBY
49
-
50
- expect_correction(<<~RUBY)
51
- RSpec.describe "Foo" do
52
- fab!(:foo)
53
- end
54
- RUBY
55
- end
56
-
57
- it "supports autocorrect when the name and fabricator don't match" do
58
- expect_offense(<<~RUBY)
59
- RSpec.describe "Foo" do
60
- fab!(:bar) { Fabricate(:foo) }
61
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:bar, :foo)`
62
- end
63
- RUBY
64
-
65
- expect_correction(<<~RUBY)
66
- RSpec.describe "Foo" do
67
- fab!(:bar, :foo)
68
- end
69
- RUBY
70
- end
71
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- it "raises an offense if add_reference is used, with or without arguments" do
9
- offenses = inspect_source(<<~RUBY)
10
- add_reference :posts, :users, foreign_key: true, null: false
11
- RUBY
12
- expect(offenses.first.message).to match(described_class::MSG)
13
- end
14
-
15
- it "raises an offense if add_belongs_to is used, with or without arguments" do
16
- offenses = inspect_source(<<~RUBY)
17
- add_belongs_to :posts, :users, foreign_key: true, null: false
18
- RUBY
19
- expect(offenses.first.message).to match(described_class::MSG)
20
- end
21
-
22
- it "raises an offense if t.references, or any variable.references is used, with or without arguments" do
23
- offenses = inspect_source(<<~RUBY)
24
- create_table do |t|
25
- t.references :topic, null: false
26
- end
27
- create_table do |mytable|
28
- mytable.references :topic, null: false
29
- end
30
- RUBY
31
- expect(offenses.count).to eq(2)
32
- expect(offenses.first.message).to match(described_class::MSG)
33
- end
34
-
35
- it "raises an offense if t.belongs_to, or any variable.belongs_to is used, with or without arguments" do
36
- offenses = inspect_source(<<~RUBY)
37
- create_table do |t|
38
- t.belongs_to :topic, null: false
39
- end
40
- create_table do |mytable|
41
- mytable.belongs_to :topic, null: false
42
- end
43
- RUBY
44
- expect(offenses.count).to eq(2)
45
- expect(offenses.first.message).to match(described_class::MSG)
46
- end
47
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- it "raises an offense if there are multisite and standard top-level describes" do
9
- offenses = inspect_source(<<~RUBY)
10
- RSpec.describe "test" do
11
- end
12
-
13
- describe "test2", type: :multisite do
14
- end
15
- RUBY
16
-
17
- expect(offenses.first.message).to match(described_class::MSG)
18
- end
19
-
20
- it "raises an offense if there are multiple multisite and standard top-level describes" do
21
- offenses = inspect_source(<<~RUBY)
22
- describe "test", type: :multisite do
23
- end
24
-
25
- describe "test2", type: :multisite do
26
- end
27
-
28
- describe "test2" do
29
- end
30
- RUBY
31
-
32
- expect(offenses.first.message).to match(described_class::MSG)
33
- end
34
-
35
- it "does not raise an offense if there are only multisite describes" do
36
- offenses = inspect_source(<<~RUBY)
37
- require "foo"
38
-
39
- describe "test", type: :multisite do
40
- describe "inner-test" do
41
- it "test" do
42
- end
43
- end
44
- end
45
-
46
- RSpec.describe "test2", type: :multisite do
47
- end
48
- RUBY
49
-
50
- expect(offenses).to eq([])
51
- end
52
-
53
- it "does not raise an offense if there are only standard describes" do
54
- offenses = inspect_source(<<~RUBY)
55
- require "rails_helper"
56
-
57
- describe "test" do
58
- end
59
-
60
- describe "test2" do
61
- RSpec.describe "inner-test" do
62
- end
63
- end
64
- RUBY
65
-
66
- expect(offenses).to eq([])
67
- end
68
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::NoMockingJobs, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- it "raises an offense if Jobs is mocked with :enqueue" do
9
- offenses = inspect_source(<<~RUBY)
10
- Jobs.expects(:enqueue)
11
- RUBY
12
-
13
- expect(offenses.first.message).to end_with(described_class::MSG)
14
- end
15
-
16
- it "raises an offense if Jobs is mocked with :enqueue_in" do
17
- offenses = inspect_source(<<~RUBY)
18
- Jobs.expects(:enqueue_in)
19
- RUBY
20
-
21
- expect(offenses.first.message).to end_with(described_class::MSG)
22
- end
23
-
24
- it "does not raise an offense if Jobs is not mocked with :enqueue or :enqueue_in" do
25
- offenses = inspect_source(<<~RUBY)
26
- Jobs.enqueue(:some_job)
27
- RUBY
28
-
29
- expect(offenses).to eq([])
30
- end
31
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- before { config["Discourse/NoResetColumnInformationInMigrations"]["Enabled"] = true }
9
-
10
- it "raises an offense if reset_column_information is used" do
11
- offenses = inspect_source(<<~RUBY)
12
- class SomeMigration < ActiveRecord::Migration[6.0]
13
- def up
14
- Post.reset_column_information
15
- end
16
- end
17
- RUBY
18
-
19
- expect(offenses.first.message).to match(described_class::MSG)
20
- end
21
-
22
- it "raise an offense if reset_column_information is used without AR model" do
23
- offenses = inspect_source(<<~RUBY)
24
- class SomeMigration < ActiveRecord::Migration[6.0]
25
- def up
26
- "post".classify.constantize.reset_column_information
27
- end
28
- end
29
- RUBY
30
-
31
- expect(offenses.first.message).to match(described_class::MSG)
32
- end
33
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::OnlyTopLevelMultisiteSpecs, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- it "raises an offense if multisite config option is used in a sub-describe" do
9
- offenses = inspect_source(<<~RUBY)
10
- describe "test" do
11
- describe "sub-test", type: :multisite do
12
- end
13
- end
14
- RUBY
15
-
16
- expect(offenses.first.message).to match(described_class::MSG)
17
- end
18
-
19
- it "raises an offense if multisite config option is used in a sub-describe (RSpec const version)" do
20
- offenses = inspect_source(<<~RUBY)
21
- RSpec.describe "test" do
22
- RSpec.describe "sub-test", type: :multisite do
23
- end
24
- end
25
- RUBY
26
-
27
- expect(offenses.first.message).to match(described_class::MSG)
28
- end
29
-
30
- it "raises an offense if multisite config option is used in an example" do
31
- offenses = inspect_source(<<~RUBY)
32
- describe "test" do
33
- it "acts as an example" do
34
- end
35
-
36
- it "does a thing", type: :multisite do
37
- end
38
- end
39
- RUBY
40
-
41
- expect(offenses.first.message).to match(described_class::MSG)
42
- end
43
-
44
- it "raises an offense if multisite config option is used in a context" do
45
- offenses = inspect_source(<<~RUBY)
46
- describe "test" do
47
- context "special circumstances", type: :multisite do
48
- end
49
- end
50
- RUBY
51
-
52
- expect(offenses.first.message).to match(described_class::MSG)
53
- end
54
-
55
- it "does not raise an offense if multisite config option is used on top-level describe" do
56
- offenses = inspect_source(<<~RUBY)
57
- describe "test", type: :multisite do
58
- describe "sub-test" do
59
- end
60
- end
61
- RUBY
62
-
63
- expect(offenses).to eq([])
64
- end
65
-
66
- it "does not raise an offense if multisite config option is used on top-level describe (RSpec const version)" do
67
- offenses = inspect_source(<<~RUBY)
68
- require "rails_helper"
69
-
70
- RSpec.describe "test", type: :multisite do
71
- describe "sub-test" do
72
- end
73
- end
74
- RUBY
75
-
76
- expect(offenses).to eq([])
77
- end
78
- end
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::Plugins::CallRequiresPlugin, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- context "when `requires_plugin` is missing" do
9
- it "registers an offense" do
10
- expect_offense(<<~RUBY)
11
- class MyController < ApplicationController
12
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/CallRequiresPlugin: Use `requires_plugin` in controllers to prevent routes from being accessible when plugin is disabled.
13
- requires_login
14
- end
15
- RUBY
16
- end
17
- end
18
-
19
- context "when `requires_plugin` is not missing" do
20
- it "does not register an offense" do
21
- expect_no_offenses(<<~RUBY)
22
- class MyController
23
- requires_plugin MyPlugin::PLUGIN_NAME
24
- requires_login
25
- end
26
- RUBY
27
- end
28
- end
29
-
30
- context "when inheriting" do
31
- let(:controllers_path) do
32
- Pathname.new("#{__dir__}/../../../../fixtures/controllers").cleanpath
33
- end
34
-
35
- before do
36
- # As we’re providing real files, we need to get rid of the default config
37
- # restricting the cop to `app/controllers/*`
38
- configuration.for_cop(cop).delete("Include")
39
- end
40
-
41
- context "when `requires_plugin` is called in a parent controller" do
42
- let(:good_controller) { controllers_path.join("good_controller.rb") }
43
-
44
- it "does not register an offense" do
45
- expect_no_offenses(good_controller.read, good_controller.to_s)
46
- end
47
- end
48
-
49
- context "when `requires_plugin` is not called in a parent controller" do
50
- let(:bad_controller) { controllers_path.join("bad_controller.rb") }
51
-
52
- it "registers an offense" do
53
- expect_offense(bad_controller.read, bad_controller.to_s)
54
- end
55
- end
56
-
57
- context "when parent controller can’t be located" do
58
- context "when parent controller is namespaced" do
59
- let(:controller) do
60
- controllers_path.join("namespaced_parent_controller.rb")
61
- end
62
-
63
- it "registers an offense" do
64
- expect_offense(controller.read, controller.to_s)
65
- end
66
- end
67
-
68
- context "when parent controller is not namespaced" do
69
- let(:controller) do
70
- controllers_path.join("inherit_from_outside_controller.rb")
71
- end
72
-
73
- it "registers an offense" do
74
- expect_offense(controller.read, controller.to_s)
75
- end
76
- end
77
- end
78
- end
79
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::Plugins::NamespaceConstants, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- context "when defining a constant outside any namespace" do
9
- it "registers an offense" do
10
- expect_offense(<<~RUBY)
11
- MY_CONSTANT = "my_value"
12
- ^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/NamespaceConstants: Don’t define constants outside a class or a module.
13
-
14
- class MyClass
15
- MY_CONSTANT = "my_value"
16
- end
17
- RUBY
18
- end
19
- end
20
-
21
- context "when defining a constant inside a class" do
22
- it "does not register an offense" do
23
- expect_no_offenses(<<~RUBY)
24
- class MyClass
25
- MY_CONSTANT = "my_value"
26
- end
27
- RUBY
28
- end
29
- end
30
-
31
- context "when defining a constant inside a module" do
32
- it "does not register an offense" do
33
- expect_no_offenses(<<~RUBY)
34
- module MyModule
35
- MY_CONSTANT = "my_value"
36
- end
37
- RUBY
38
- end
39
- end
40
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::Plugins::NamespaceMethods, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- context "when defining a method outside any namespace" do
9
- it "registers an offense" do
10
- expect_offense(<<~RUBY)
11
- def my_method
12
- ^^^^^^^^^^^^^ Discourse/Plugins/NamespaceMethods: Don’t define methods outside a class or a module.
13
- "my_value"
14
- end
15
-
16
- class MyClass
17
- def my_method
18
- "my_method"
19
- end
20
- end
21
- RUBY
22
- end
23
- end
24
-
25
- context "when defining a method inside a class" do
26
- context "when defining an instance method" do
27
- it "does not register an offense" do
28
- expect_no_offenses(<<~RUBY)
29
- class MyClass
30
- def my_method
31
- "my_value"
32
- end
33
- end
34
- RUBY
35
- end
36
- end
37
-
38
- context "when defining a class method" do
39
- it "does not register an offense" do
40
- expect_no_offenses(<<~RUBY)
41
- class MyClass
42
- class << self
43
- def my_method
44
- "my_value"
45
- end
46
-
47
- def another_method
48
- "plop"
49
- end
50
- end
51
- end
52
- RUBY
53
- end
54
- end
55
- end
56
-
57
- context "when defining a method inside a module" do
58
- context "when defining an instance method" do
59
- it "does not register an offense" do
60
- expect_no_offenses(<<~RUBY)
61
- module MyModule
62
- def my_method
63
- "my_value"
64
- end
65
- end
66
- RUBY
67
- end
68
- end
69
-
70
- context "when defining a class method" do
71
- it "does not register an offense" do
72
- expect_no_offenses(<<~RUBY)
73
- module MyModule
74
- class << self
75
- def my_method
76
- "my_value"
77
- end
78
- end
79
- end
80
- RUBY
81
- end
82
- end
83
- end
84
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::Plugins::NoMonkeyPatching, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- context "when outside `plugin.rb`" do
9
- it "does not register an offense" do
10
- expect_no_offenses(<<~RUBY, "my_class.rb")
11
- class ::MyClass
12
- def my_method
13
- "my_value"
14
- end
15
- end
16
-
17
- class AnotherClass
18
- def my_method
19
- "my_value"
20
- end
21
- end
22
- RUBY
23
- end
24
- end
25
-
26
- context "when inside `plugin.rb`" do
27
- context "when opening an existing class" do
28
- it "registers an offense" do
29
- expect_offense(<<~RUBY, "plugin.rb")
30
- after_initialize do
31
- module MyPlugin
32
- class Engine < Rails::Engine
33
- isolate_namespace MyPlugin
34
- end
35
- end
36
-
37
- class ::Topic
38
- ^^^^^^^^^^^^^ Discourse/Plugins/NoMonkeyPatching: Don’t reopen existing classes. [...]
39
- def self.new_method
40
- :new_value
41
- end
42
-
43
- def my_new_method
44
- "my_new_value"
45
- end
46
- end
47
- end
48
- RUBY
49
- end
50
- end
51
-
52
- context "when opening an existing serializer" do
53
- it "registers an offense" do
54
- expect_offense(<<~RUBY, "plugin.rb")
55
- class ::TopicSerializer
56
- ^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/NoMonkeyPatching: Don’t reopen serializers. [...]
57
- def new_attribute
58
- "my_attribute"
59
- end
60
- end
61
- RUBY
62
- end
63
- end
64
-
65
- context "when calling `.class_eval` on a class" do
66
- it "registers an offense" do
67
- expect_offense(<<~RUBY)
68
- User.class_eval do
69
- ^^^^^^^^^^^^^^^ Discourse/Plugins/NoMonkeyPatching: Don’t call `class_eval`. [...]
70
- def a_new_method
71
- :new_value
72
- end
73
- end
74
- RUBY
75
- end
76
- end
77
-
78
- context "when calling `.class_eval` on a serializer" do
79
- it "registers an offense" do
80
- expect_offense(<<~RUBY)
81
- UserSerializer.class_eval do
82
- ^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/NoMonkeyPatching: Don’t call `class_eval` on a serializer. [...]
83
- def a_new_method
84
- :new_value
85
- end
86
- end
87
- RUBY
88
- end
89
- end
90
- end
91
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::Plugins::UsePluginInstanceOn, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- context "when outside `plugin.rb`" do
9
- context "when `DiscourseEvent.on` is called" do
10
- it "registers an offense" do
11
- expect_offense(<<~RUBY, "another_file.rb")
12
- DiscourseEvent.on(:topic_status_updated) { do_something }
13
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/UsePluginInstanceOn: Don’t call `DiscourseEvent.on` outside `plugin.rb`.
14
- RUBY
15
- end
16
- end
17
- end
18
-
19
- context "when inside `plugin.rb`" do
20
- context "when `DiscourseEvent.on` is called" do
21
- it "registers an offense" do
22
- expect_offense(<<~RUBY, "plugin.rb")
23
- DiscourseEvent.on(:topic_status_updated) { do_something }
24
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/UsePluginInstanceOn: Use `on` instead of `DiscourseEvent.on` [...]
25
- RUBY
26
- end
27
- end
28
-
29
- context "when `on` is called" do
30
- it "does not register an offense" do
31
- expect_no_offenses(<<~RUBY, "plugin.rb")
32
- on(:topic_status_updated) { do_something }
33
- RUBY
34
- end
35
- end
36
- end
37
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RuboCop::Cop::Discourse::Plugins::UseRequireRelative, :config do
4
- subject(:cop) { described_class.new(config) }
5
-
6
- let(:config) { RuboCop::Config.new }
7
-
8
- context "when using `load`" do
9
- it "registers an offense" do
10
- expect_offense(<<~RUBY)
11
- load File.expand_path("../app/jobs/onceoff/voting_ensure_consistency.rb", __FILE__)
12
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/UseRequireRelative: Use `require_relative` instead of `load`.
13
- RUBY
14
- end
15
- end
16
-
17
- context "when using `require_relative`" do
18
- it "does not register an offense" do
19
- expect_no_offenses(<<~RUBY)
20
- require_relative "app/controllers/encrypt_controller.rb"
21
- RUBY
22
- end
23
- end
24
- end