|
10 | 10 | it 'registers an offense' do |
11 | 11 | expect_offense(<<~RUBY) |
12 | 12 | enum status: %i[active archived] |
13 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
| 13 | + ^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
14 | 14 | RUBY |
15 | 15 | end |
16 | 16 | end |
|
19 | 19 | it 'registers an offense' do |
20 | 20 | expect_offense(<<~RUBY) |
21 | 21 | enum status: %w[active archived] |
22 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
| 22 | + ^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
23 | 23 | RUBY |
24 | 24 | end |
25 | 25 | end |
|
28 | 28 | it 'registers an offense' do |
29 | 29 | expect_offense(<<~RUBY) |
30 | 30 | enum status: %i(active archived) |
31 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
| 31 | + ^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
32 | 32 | RUBY |
33 | 33 | end |
34 | 34 | end |
|
37 | 37 | it 'registers an offense' do |
38 | 38 | expect_offense(<<~RUBY) |
39 | 39 | enum status: %w(active archived) |
40 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
| 40 | + ^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
41 | 41 | RUBY |
42 | 42 | end |
43 | 43 | end |
|
46 | 46 | it 'registers an offense' do |
47 | 47 | expect_offense(<<~RUBY) |
48 | 48 | enum status: [:active, :archived] |
49 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
| 49 | + ^^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
| 50 | + RUBY |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + context 'when the enum name is a string' do |
| 55 | + it 'registers an offense' do |
| 56 | + expect_offense(<<~RUBY) |
| 57 | + enum "status" => %i[active archived] |
| 58 | + ^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
| 59 | + RUBY |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + context 'when the enum name is not a literal' do |
| 64 | + it 'registers an offense' do |
| 65 | + expect_offense(<<~RUBY) |
| 66 | + enum KEY => %i[active archived] |
| 67 | + ^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `KEY` enum declaration. Use hash syntax instead. |
| 68 | + RUBY |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context 'with multiple enum definition for a `enum` method call' do |
| 73 | + it 'registers an offense' do |
| 74 | + expect_offense(<<~RUBY) |
| 75 | + enum status: %i[active archived], |
| 76 | + ^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `status` enum declaration. Use hash syntax instead. |
| 77 | + role: %i[owner member guest] |
| 78 | + ^^^^^^^^^^^^^^^^^^^^^^ Enum defined as an array found in `role` enum declaration. Use hash syntax instead. |
50 | 79 | RUBY |
51 | 80 | end |
52 | 81 | end |
|
0 commit comments