/
colon_method_definition_spec.rb
57 lines (51 loc) · 1.23 KB
/
colon_method_definition_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ColonMethodDefinition do
subject(:cop) { described_class.new }
it 'accepts a class method defined using .' do
expect_no_offenses(<<-RUBY.strip_indent)
class Foo
def self.bar
something
end
end
RUBY
end
context 'using self' do
it 'registers an offense for a class method defined using ::' do
expect_offense(<<-RUBY.strip_indent)
class Foo
def self::bar
^^ Do not use `::` for defining class methods.
something
end
end
RUBY
expect_correction(<<-RUBY.strip_indent)
class Foo
def self.bar
something
end
end
RUBY
end
end
context 'using the class name' do
it 'registers an offense for a class method defined using ::' do
expect_offense(<<-RUBY.strip_indent)
class Foo
def Foo::bar
^^ Do not use `::` for defining class methods.
something
end
end
RUBY
expect_correction(<<-RUBY.strip_indent)
class Foo
def Foo.bar
something
end
end
RUBY
end
end
end