forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 2
/
def_with_parentheses_spec.rb
49 lines (42 loc) · 1.04 KB
/
def_with_parentheses_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::DefWithParentheses, :config do
it 'reports an offense for def with empty parens' do
expect_offense(<<~RUBY)
def func()
^^ Omit the parentheses in defs when the method doesn't accept any arguments.
end
RUBY
expect_correction(<<~RUBY)
def func
end
RUBY
end
it 'reports an offense for class def with empty parens' do
expect_offense(<<~RUBY)
def Test.func()
^^ Omit the parentheses in defs when the method doesn't accept any arguments.
something
end
RUBY
expect_correction(<<~RUBY)
def Test.func
something
end
RUBY
end
it 'accepts def with arg and parens' do
expect_no_offenses(<<~RUBY)
def func(a)
end
RUBY
end
it 'accepts def without arguments' do
expect_no_offenses(<<~RUBY)
def func
end
RUBY
end
it 'accepts empty parentheses in one liners' do
expect_no_offenses("def to_s() join '/' end")
end
end