/
top_level_hash_with_indifferent_access_spec.rb
69 lines (60 loc) · 1.99 KB
/
top_level_hash_with_indifferent_access_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Rails::TopLevelHashWithIndifferentAccess, :config, :rails51 do
context 'with top-level HashWithIndifferentAccess' do
it 'registers and corrects an offense' do
expect_offense(<<~RUBY)
HashWithIndifferentAccess.new(foo: 'bar')
^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid top-level `HashWithIndifferentAccess`.
RUBY
expect_correction(<<~RUBY)
ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar')
RUBY
end
end
context 'with top-level ::HashWithIndifferentAccess' do
it 'registers and corrects an offense' do
expect_offense(<<~RUBY)
::HashWithIndifferentAccess.new(foo: 'bar')
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid top-level `HashWithIndifferentAccess`.
RUBY
expect_correction(<<~RUBY)
::ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar')
RUBY
end
end
context 'with top-level `HashWithIndifferentAccess` without method call' do
it 'registers and corrects an offense' do
expect_offense(<<~RUBY)
HashWithIndifferentAccess
^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid top-level `HashWithIndifferentAccess`.
RUBY
expect_correction(<<~RUBY)
ActiveSupport::HashWithIndifferentAccess
RUBY
end
end
context 'with ActiveSupport::HashWithIndifferentAccess' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
ActiveSupport::HashWithIndifferentAccess.new(foo: 'bar')
RUBY
end
end
context 'with `HashWithIndifferentAccess` under the namespace' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
module CoreExt
class HashWithIndifferentAccess
end
end
RUBY
end
end
context 'with ActiveSupport::HashWithIndifferentAccess on Rails 5.0', :rails50 do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
HashWithIndifferentAccess.new(foo: 'bar')
RUBY
end
end
end