-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
def_parentheses_spec.rb
48 lines (41 loc) · 1.35 KB
/
def_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
# encoding: utf-8
require 'spec_helper'
module Rubocop
module Cop
describe DefParentheses do
let (:def_par) { DefParentheses.new }
it 'reports an offence for def with parameters but no parens' do
src = ['def func a, b',
'end']
inspect_source(def_par, '', src)
def_par.offences.map(&:message).should ==
['Use def with parentheses when there are arguments.']
end
it 'reports an offence for def with empty parens' do
src = ['def func()',
'end']
inspect_source(def_par, '', src)
def_par.offences.map(&:message).should ==
["Omit the parentheses in defs when the method doesn't accept any " +
"arguments."]
end
it 'accepts def with arg and parens' do
src = ['def func(a)',
'end']
inspect_source(def_par, '', src)
def_par.offences.map(&:message).should == []
end
it 'accepts def with no args and no parens' do
src = ['def func',
'end']
inspect_source(def_par, '', src)
def_par.offences.map(&:message).should == []
end
it 'accepts empty parentheses in one liners' do
src = ["def to_s() join '/' end"]
inspect_source(def_par, '', src)
def_par.offences.map(&:message).should == []
end
end
end
end