Skip to content

Commit

Permalink
Complete branch coverage for VoidExpect and ContextWording
Browse files Browse the repository at this point in the history
  • Loading branch information
corsonknowles committed Oct 14, 2024
1 parent a95f2f0 commit 89424c5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spec/rubocop/cop/rspec/context_wording_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,17 @@
end
end
end

context 'when `AllowedPatterns:` and `Prefixes:` are both empty' do
let(:cop_config) do
{ 'Prefixes' => [], 'AllowedPatterns' => [] }
end

it 'skips any description' do
expect_no_offenses(<<~RUBY)
context 'arbitrary text' do
end
RUBY
end
end
end
39 changes: 39 additions & 0 deletions spec/rubocop/cop/rspec/void_expect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,43 @@
end
RUBY
end

it 'ignores unrelated method named expect in an example block' do
expect_no_offenses(<<~RUBY)
it 'something' do
MyObject.expect
end
RUBY
end

it 'flags bare `expect` in example block' do
expect_offense(<<~RUBY)
it 'something' do
expect
^^^^^^ Do not use `expect()` without `.to` or `.not_to`. Chain the methods or remove it.
end
RUBY
end

context 'when expect has no parent node' do
it 'still registers an offense' do
expect_offense(<<~RUBY)
expect(something)
^^^^^^^^^^^^^^^^^ Do not use `expect()` without `.to` or `.not_to`. Chain the methods or remove it.
RUBY
end

it 'rejects bare expect with no arguments' do
expect_offense(<<~RUBY)
expect
^^^^^^ Do not use `expect()` without `.to` or `.not_to`. Chain the methods or remove it.
RUBY
end

it 'ignores unrelated expect method' do
expect_no_offenses(<<~RUBY)
MyObject.expect
RUBY
end
end
end

0 comments on commit 89424c5

Please sign in to comment.