Skip to content

Commit

Permalink
Merge pull request #1367 from ydah/doc/header_comment
Browse files Browse the repository at this point in the history
Fix cop header comment
  • Loading branch information
bquorning committed Aug 25, 2022
2 parents 425bc13 + e7e5444 commit 99bc4e2
Show file tree
Hide file tree
Showing 71 changed files with 247 additions and 244 deletions.
47 changes: 23 additions & 24 deletions docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1993,16 +1993,15 @@ Checks for before/around/after hooks that come after an example.

[source,ruby]
----
# Bad
# bad
it 'checks what foo does' do
expect(foo).to be
end
before { prepare }
after { clean_up }
# Good
# good
before { prepare }
after { clean_up }
Expand Down Expand Up @@ -2432,28 +2431,28 @@ Enforce that subject is the first definition in the test.
[source,ruby]
----
# bad
let(:params) { blah }
subject { described_class.new(params) }
let(:params) { blah }
subject { described_class.new(params) }
before { do_something }
subject { described_class.new(params) }
before { do_something }
subject { described_class.new(params) }
it { expect_something }
subject { described_class.new(params) }
it { expect_something_else }
it { expect_something }
subject { described_class.new(params) }
it { expect_something_else }
# good
subject { described_class.new(params) }
let(:params) { blah }
subject { described_class.new(params) }
let(:params) { blah }
# good
subject { described_class.new(params) }
before { do_something }
subject { described_class.new(params) }
before { do_something }
# good
subject { described_class.new(params) }
it { expect_something }
it { expect_something_else }
subject { described_class.new(params) }
it { expect_something }
it { expect_something_else }
----

=== References
Expand Down Expand Up @@ -2595,7 +2594,7 @@ Checks for `let` definitions that come after an example.

[source,ruby]
----
# Bad
# bad
let(:foo) { bar }
it 'checks what foo does' do
Expand All @@ -2608,7 +2607,7 @@ it 'checks what some does' do
expect(some).to be
end
# Good
# good
let(:foo) { bar }
let(:some) { other }
Expand Down Expand Up @@ -2643,20 +2642,20 @@ Checks unreferenced `let!` calls being used for test setup.

[source,ruby]
----
# Bad
# bad
let!(:my_widget) { create(:widget) }
it 'counts widgets' do
expect(Widget.count).to eq(1)
end
# Good
# good
it 'counts widgets' do
create(:widget)
expect(Widget.count).to eq(1)
end
# Good
# good
before { create(:widget) }
it 'counts widgets' do
Expand Down Expand Up @@ -2689,7 +2688,7 @@ Check that chains of messages are not being stubbed.
# bad
allow(foo).to receive_message_chain(:bar, :baz).and_return(42)
# better
# good
thing = Thing.new(baz: 42)
allow(foo).to receive(:bar).and_return(thing)
----
Expand Down Expand Up @@ -3294,7 +3293,7 @@ context 'when using some feature' do
end
end
# better
# good
context 'using some feature as an admin' do
let(:some) { :various }
let(:feature) { :setup }
Expand Down
17 changes: 8 additions & 9 deletions lib/rubocop/cop/rspec/align_left_let_brace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ module RSpec
# Checks that left braces for adjacent single line lets are aligned.
#
# @example
# # bad
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
# # bad
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
# # good
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
# # good
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
class AlignLeftLetBrace < Base
extend AutoCorrector
Expand Down
17 changes: 8 additions & 9 deletions lib/rubocop/cop/rspec/align_right_let_brace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ module RSpec
# Checks that right braces for adjacent single line lets are aligned.
#
# @example
# # bad
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
# # bad
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
# # good
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
# # good
# let(:foobar) { blahblah }
# let(:baz) { bar }
# let(:a) { b }
#
class AlignRightLetBrace < Base
extend AutoCorrector
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/any_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module RSpec
# allow(my_instance).to receive(:foo)
# end
# end
#
class AnyInstance < Base
MSG = 'Avoid stubbing using `%<method>s`.'
RESTRICT_ON_SEND = %i[
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/around_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module RSpec
# some_method
# test.run
# end
#
class AroundBlock < Base
MSG_NO_ARG = 'Test object should be passed to around block.'
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` ' \
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop/cop/rspec/be.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module RSpec
# cases it's better to specify what exactly is the expected value.
#
# @example
#
# # bad
# expect(foo).to be
#
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop/cop/rspec/be_eq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module RSpec
# the `be` matcher is preferable as it is a more strict test.
#
# @example
#
# # bad
# expect(foo).to eq(true)
# expect(foo).to eq(false)
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop/cop/rspec/be_eql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module RSpec
# preferable as it is a more strict test.
#
# @example
#
# # bad
# expect(foo).to eql(1)
# expect(foo).to eql(1.0)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/before_after_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module RSpec
# before(:each) { Widget.create }
# after(:each) { Widget.delete_all }
# end
#
class BeforeAfterAll < Base
MSG = 'Beware of using `%<hook>s` as it may cause state to leak ' \
'between tests. If you are using `rspec-rails`, and ' \
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/capybara/feature_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Capybara
# # ...
# end
# end
#
class FeatureMethods < Base
extend AutoCorrector
include InsideExampleGroup
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop/cop/rspec/capybara/visibility_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Capybara
# https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
#
# @example
#
# # bad
# expect(page).to have_selector('.foo', visible: false)
# expect(page).to have_css('.foo', visible: true)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/context_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module RSpec
# describe '.foo_bar' do
# # ...
# end
#
class ContextMethod < Base
extend AutoCorrector

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/context_wording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module RSpec
# @see http://www.betterspecs.org/#contexts
#
# @example `Prefixes` configuration
#
# # .rubocop.yml
# # RSpec/ContextWording:
# # Prefixes:
Expand All @@ -35,6 +34,7 @@ module RSpec
# context 'when the display name is not present' do
# # ...
# end
#
class ContextWording < Base
MSG = 'Start context description with %<prefixes>s.'

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/describe_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module RSpec
# Ignores Rails and Aruba `type` metadata by default.
#
# @example `IgnoredMetadata` configuration
#
# # .rubocop.yml
# # RSpec/DescribeClass:
# # IgnoredMetadata:
Expand All @@ -34,6 +33,7 @@ module RSpec
#
# describe "A feature example", type: :feature do
# end
#
class DescribeClass < Base
include TopLevelGroup

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/describe_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module RSpec
#
# describe MyClass, '.my_class_method' do
# end
#
class DescribeMethod < Base
include TopLevelGroup

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/dialect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module RSpec
# describe 'display name presence' do
# # ...
# end
#
class Dialect < Base
extend AutoCorrector
include MethodPreference
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/empty_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module RSpec
# Checks if an example group does not include any tests.
#
# @example usage
#
# # bad
# describe Bacon do
# let(:bacon) { Bacon.new(chunkiness) }
Expand Down Expand Up @@ -35,6 +34,7 @@ module RSpec
# describe Bacon do
# pending 'will add tests later'
# end
#
class EmptyExampleGroup < Base
extend AutoCorrector

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/empty_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module RSpec
# create_feed
# end
# after(:all) { cleanup_feed }
#
class EmptyHook < Base
extend AutoCorrector
include RuboCop::Cop::RangeHelp
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop/cop/rspec/empty_line_after_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module RSpec
# end
#
# @example with AllowConsecutiveOneLiners configuration
#
# # rubocop.yml
# # RSpec/EmptyLineAfterExample:
# # AllowConsecutiveOneLiners: false
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/empty_line_after_final_let.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module RSpec
# let(:something) { other }
#
# it { does_something }
#
class EmptyLineAfterFinalLet < Base
extend AutoCorrector
include EmptyLineSeparation
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/empty_line_after_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module RSpec
# after { do_something }
#
# it { does_something }
#
class EmptyLineAfterHook < Base
extend AutoCorrector
include ConfigurableEnforcedStyle
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/empty_line_after_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module RSpec
# subject(:obj) { described_class }
#
# let(:foo) { bar }
#
class EmptyLineAfterSubject < Base
extend AutoCorrector
include EmptyLineSeparation
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/example_length.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module RSpec
# content.
# HEREDOC
# end # 5 points
#
class ExampleLength < Base
include CodeLength

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/example_without_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module RSpec
# result = service.call
# expect(result).to be(true)
# end
#
class ExampleWithoutDescription < Base
include ConfigurableEnforcedStyle

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/example_wording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module RSpec
# # good
# it 'does things' do
# end
#
class ExampleWording < Base
extend AutoCorrector

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/excessive_docstring_spacing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module RSpec
# # good
# context 'when a condition is met' do
# end
#
class ExcessiveDocstringSpacing < Base
extend AutoCorrector

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/expect_in_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module RSpec
# it do
# expect(something).to eq 'foo'
# end
#
class ExpectInHook < Base
MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/expect_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module RSpec
#
# # good
# expect { my_app.print_report }.to output('Hello World').to_stdout
#
class ExpectOutput < Base
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` ' \
'instead of mutating $%<name>s.'
Expand Down

0 comments on commit 99bc4e2

Please sign in to comment.