Skip to content

Commit

Permalink
Merge pull request #1674 from tmaier/tmaier-1673-fix-focus
Browse files Browse the repository at this point in the history
Update RSpec/Focus to support shared_context and shared_examples
  • Loading branch information
ydah authored Jul 24, 2023
2 parents b03a388 + 8e68e58 commit 2b0371a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Add `AllowedIdentifiers` and `AllowedPatterns` configuration option to `RSpec/IndexedLet`. ([@ydah])
- Fix `RSpec/NamedSubject` when block has no body. ([@splattael])
- Fix `RSpec/LetBeforeExamples` autocorrect incompatible with `RSpec/ScatteredLet` autocorrect. ([@ydah])
- Update `RSpec/Focus` to support `shared_context` and `shared_examples` ([@tmaier])

## 2.22.0 (2023-05-06)

Expand Down Expand Up @@ -879,6 +880,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@telmofcosta]: https://github.com/telmofcosta
[@tietew]: https://github.com/Tietew
[@timrogers]: https://github.com/timrogers
[@tmaier]: https://github.com/tmaier
[@topalovic]: https://github.com/topalovic
[@twalpole]: https://github.com/twalpole
[@vzvu3k6k]: https://github.com/vzvu3k6k
Expand Down
12 changes: 12 additions & 0 deletions docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,18 @@ fdescribe 'test' do; end
# good
describe 'test' do; end
# bad
shared_examples 'test', focus: true do; end
# good
shared_examples 'test' do; end
# bad
shared_context 'test', focus: true do; end
# good
shared_context 'test' do; end
# bad (does not support autocorrection)
focus 'test' do; end
----
Expand Down
13 changes: 13 additions & 0 deletions lib/rubocop/cop/rspec/focus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ module RSpec
# # good
# describe 'test' do; end
#
# # bad
# shared_examples 'test', focus: true do; end
#
# # good
# shared_examples 'test' do; end
#
# # bad
# shared_context 'test', focus: true do; end
#
# # good
# shared_context 'test' do; end
#
# # bad (does not support autocorrection)
# focus 'test' do; end
#
Expand All @@ -51,6 +63,7 @@ class Focus < Base
#Examples.regular
#Examples.skipped
#Examples.pending
#SharedGroups.all
}
PATTERN

Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/rspec/focus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
^^^^^^^^^^^ Focused spec found.
pending 'test', meta: true, focus: true do; end
^^^^^^^^^^^ Focused spec found.
shared_examples 'test', meta: true, focus: true do; end
^^^^^^^^^^^ Focused spec found.
shared_context 'test', meta: true, focus: true do; end
^^^^^^^^^^^ Focused spec found.
RUBY

expect_correction(<<-RUBY)
Expand All @@ -58,6 +62,8 @@
xfeature 'test', meta: true do; end
xscenario 'test', meta: true do; end
pending 'test', meta: true do; end
shared_examples 'test', meta: true do; end
shared_context 'test', meta: true do; end
RUBY
end

Expand Down Expand Up @@ -97,6 +103,10 @@
^^^^^^ Focused spec found.
pending 'test', :focus do; end
^^^^^^ Focused spec found.
shared_examples 'test', :focus do; end
^^^^^^ Focused spec found.
shared_context 'test', :focus do; end
^^^^^^ Focused spec found.
RUBY

expect_correction(<<-RUBY)
Expand All @@ -117,6 +127,8 @@
xcontext 'test' do; end
it 'test' do; end
pending 'test' do; end
shared_examples 'test' do; end
shared_context 'test' do; end
RUBY
end
# rubocop:enable RSpec/ExampleLength
Expand All @@ -138,6 +150,8 @@
it 'test' do; end
example_group 'test' do; end
xdescribe 'test' do; end
shared_examples 'test' do; end
shared_context 'test' do; end
RUBY
end

Expand Down

0 comments on commit 2b0371a

Please sign in to comment.