/
empty_block_parameter_spec.rb
89 lines (74 loc) · 2.1 KB
/
empty_block_parameter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::EmptyBlockParameter do
subject(:cop) { described_class.new(config) }
let(:config) { RuboCop::Config.new }
it 'registers an offense for an empty block parameter with do-end wtyle' do
expect_offense(<<-RUBY.strip_indent)
a do ||
^^ Omit pipes for the empty block parameters.
end
RUBY
expect_correction(<<-RUBY.strip_indent)
a do
end
RUBY
end
it 'registers an offense for an empty block parameter with {} style' do
expect_offense(<<-RUBY.strip_indent)
a { || do_something }
^^ Omit pipes for the empty block parameters.
RUBY
expect_correction(<<-RUBY.strip_indent)
a { do_something }
RUBY
end
it 'registers an offense for an empty block parameter with super' do
expect_offense(<<-RUBY.strip_indent)
def foo
super { || do_something }
^^ Omit pipes for the empty block parameters.
end
RUBY
expect_correction(<<-RUBY.strip_indent)
def foo
super { do_something }
end
RUBY
end
it 'registers an offense for an empty block parameter with lambda' do
expect_offense(<<-RUBY.strip_indent)
lambda { || do_something }
^^ Omit pipes for the empty block parameters.
RUBY
expect_correction(<<-RUBY.strip_indent)
lambda { do_something }
RUBY
end
it 'accepts a block that is do-end style without parameter' do
expect_no_offenses(<<-RUBY.strip_indent)
a do
end
RUBY
end
it 'accepts a block that is {} style without parameter' do
expect_no_offenses(<<-RUBY.strip_indent)
a { }
RUBY
end
it 'accepts a non-empty block parameter with do-end style' do
expect_no_offenses(<<-RUBY.strip_indent)
a do |x|
end
RUBY
end
it 'accepts a non-empty block parameter with {} style' do
expect_no_offenses(<<-RUBY.strip_indent)
a { |x| }
RUBY
end
it 'accepts an empty block parameter with a lambda' do
expect_no_offenses(<<-RUBY.strip_indent)
-> () { do_something }
RUBY
end
end