Skip to content

Commit

Permalink
Update void_expect_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
corsonknowles committed Oct 14, 2024
1 parent b94bdb6 commit d99ad1c
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions spec/rubocop/cop/rspec/void_expect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,50 @@
RUBY
end

describe '#void?' do
it 'returns true for an `expect` node with no parent' do
source = 'expect'
node = parse_source(source).ast
expect(cop.send(:void?, node)).to be true
it 'ignores unrelated expect method in an it block' do
expect_no_offenses(<<~RUBY)
it 'something' do
MyObject.expect
end
RUBY
end

it 'rejects bare `expect` in an it 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

it 'rejects bare `expect` in a block' do
expect_offense(<<~RUBY)
method { expect }
^^^^^^ Do not use `expect()` without `.to` or `.not_to`. Chain the methods or remove it.
RUBY
end

it 'accepts expect.to with no arguments' do
expect_no_offenses(<<~RUBY)
it 'something' do
expect.to
end
RUBY
end

it 'accepts expect.to with no arguments in a block' do
expect_no_offenses(<<~RUBY)
method { expect.to }
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
end
end

0 comments on commit d99ad1c

Please sign in to comment.