Skip to content

Commit

Permalink
Lint/EmptyWhen: improve test suite (currently failing) [rubocop#7999]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Jul 4, 2020
1 parent 3aeadd9 commit 0fa2c06
Showing 1 changed file with 144 additions and 81 deletions.
225 changes: 144 additions & 81 deletions spec/rubocop/cop/lint/empty_when_spec.rb
Expand Up @@ -38,67 +38,156 @@

let(:message) { 'Avoid `when` branches without a body.' }

context 'when a `when` body is missing' do
it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar then 1
when :baz # nothing
end
RUBY
context 'when AllowComments is false' do
let(:cop_config) { {'AllowComments' => false} }

context 'when a `when` body is missing' do
it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar then 1
when :baz # nothing
end
RUBY

it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar then 1
when :baz # nothing
else 3
end
RUBY
it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar then 1
when :baz # nothing
else 3
end
RUBY

it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar then 1
when :baz then # nothing
end
RUBY
it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar then 1
when :baz then # nothing
end
RUBY

it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar then 1
when :baz then # nothing
else 3
end
RUBY
it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar then 1
when :baz then # nothing
else 3
end
RUBY

it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar
1
when :baz
# nothing
end
RUBY

it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar
1
when :baz
# nothing
else
3
end
RUBY
end
end

it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar
1
when :baz
# nothing
end
RUBY
context 'when AllowComments is true' do
let(:cop_config) { {'AllowComments' => true} }

it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar
1
when :baz
# nothing
else
3
end
RUBY
context 'when a `when` body is missing' do
it_behaves_like 'code without offense', <<~RUBY
case foo
when :bar then 1
when :baz # nothing
end
RUBY

it_behaves_like 'code with offense', <<~RUBY
case
when :bar
1
when :baz
# nothing
else
3
end
RUBY
it_behaves_like 'code without offense', <<~RUBY
case foo
when :bar then 1
when :baz # nothing
else 3
end
RUBY

it_behaves_like 'code without offense', <<~RUBY
case foo
when :bar then 1
when :baz then # nothing
end
RUBY

it_behaves_like 'code without offense', <<~RUBY
case foo
when :bar then 1
when :baz then # nothing
else 3
end
RUBY

it_behaves_like 'code without offense', <<~RUBY
case foo
when :bar
1
when :baz
# nothing
end
RUBY

it_behaves_like 'code without offense', <<~RUBY
case foo
when :bar
1
when :baz
# nothing
end
RUBY

it_behaves_like 'code with offense', <<~RUBY
case foo
when :bar
1
when :baz
when :quz # some comment
2
end
RUBY

it_behaves_like 'code without offense', <<~RUBY
case foo
when :bar
1
when :baz
# nothing
else
3
end
RUBY

it_behaves_like 'code without offense', <<~RUBY
case
when :bar
1
when :baz
# nothing
else
3
end
RUBY

it_behaves_like 'code with offense', <<~RUBY
case condition
when foo
# do something
do_something
when bar
end
RUBY
end
end

context 'when a `when` body is present' do
Expand Down Expand Up @@ -147,30 +236,4 @@
end
RUBY
end

context 'when `AllowComments: true`' do
let(:cop_config) { { 'AllowComments' => true } }

it_behaves_like 'code without offense', <<~RUBY
case condition
when foo
do_something
when bar
# do nothing
end
RUBY
end

context 'when `AllowComments: false`' do
let(:cop_config) { { 'AllowComments' => false } }

it_behaves_like 'code with offense', <<~RUBY
case condition
when foo
do_something
when bar
# do nothing
end
RUBY
end
end

0 comments on commit 0fa2c06

Please sign in to comment.