|
140 | 140 | end
|
141 | 141 | end
|
142 | 142 |
|
| 143 | + context 'when using File.join with Rails.root and an empty string as a path' do |
| 144 | + it 'does not register an offense' do |
| 145 | + expect_no_offenses(<<~RUBY) |
| 146 | + File.join(Rails.root, "") |
| 147 | + RUBY |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | + context 'when using File.join with Rails.root and a single forward slash as a path' do |
| 152 | + it 'does not register an offense' do |
| 153 | + expect_no_offenses(<<~RUBY) |
| 154 | + File.join(Rails.root, "/") |
| 155 | + RUBY |
| 156 | + end |
| 157 | + end |
| 158 | + |
| 159 | + context 'when using File.join with Rails.root and a string path ending in a slash' do |
| 160 | + it 'does not register an offense' do |
| 161 | + expect_no_offenses(<<~RUBY) |
| 162 | + File.join(Rails.root, 'app/') |
| 163 | + RUBY |
| 164 | + end |
| 165 | + end |
| 166 | + |
| 167 | + context 'when using File.join with Rails.root and multiple string paths with different trailing slash placements' do |
| 168 | + it 'does not register an offense' do |
| 169 | + expect_no_offenses(<<~RUBY) |
| 170 | + File.join(Rails.root, 'app', 'models/') |
| 171 | + RUBY |
| 172 | + |
| 173 | + expect_no_offenses(<<~RUBY) |
| 174 | + File.join(Rails.root, 'app/', 'models') |
| 175 | + RUBY |
| 176 | + |
| 177 | + expect_no_offenses(<<~RUBY) |
| 178 | + File.join(Rails.root, 'app/', 'models/') |
| 179 | + RUBY |
| 180 | + |
| 181 | + expect_no_offenses(<<~RUBY) |
| 182 | + File.join(Rails.root, 'app/', '/models') |
| 183 | + RUBY |
| 184 | + |
| 185 | + expect_no_offenses(<<~RUBY) |
| 186 | + File.join(Rails.root, '/app', 'models/') |
| 187 | + RUBY |
| 188 | + end |
| 189 | + end |
| 190 | + |
| 191 | + context 'when using File.join with Rails.root and string paths with one or more end with a trailing slash' do |
| 192 | + it 'does not register an offense' do |
| 193 | + expect_no_offenses(<<~RUBY) |
| 194 | + File.join(Rails.root, 'app/models/', 'goober') |
| 195 | + RUBY |
| 196 | + |
| 197 | + expect_no_offenses(<<~RUBY) |
| 198 | + File.join(Rails.root, 'app/models/', '/goober') |
| 199 | + RUBY |
| 200 | + |
| 201 | + expect_no_offenses(<<~RUBY) |
| 202 | + File.join(Rails.root, 'app/models', 'goober/') |
| 203 | + RUBY |
| 204 | + |
| 205 | + expect_no_offenses(<<~RUBY) |
| 206 | + File.join(Rails.root, 'app/models/', 'goober/') |
| 207 | + RUBY |
| 208 | + end |
| 209 | + end |
| 210 | + |
| 211 | + context 'when using File.join with Rails.root and an empty last argument' do |
| 212 | + it 'does not register an offense' do |
| 213 | + expect_no_offenses(<<~RUBY) |
| 214 | + File.join(Rails.root, "app", "") |
| 215 | + RUBY |
| 216 | + end |
| 217 | + end |
| 218 | + |
| 219 | + context 'when using File.join with Rails.root and a single forward slash as the last argument' do |
| 220 | + it 'does not register an offense' do |
| 221 | + expect_no_offenses(<<~RUBY) |
| 222 | + File.join(Rails.root, 'app', '/') |
| 223 | + RUBY |
| 224 | + end |
| 225 | + end |
| 226 | + |
| 227 | + context 'when using Rails.root.join with a directory ending with a slash' do |
| 228 | + it 'does not register an offense' do |
| 229 | + expect_no_offenses(<<~RUBY) |
| 230 | + Rails.root.join("app/").to_s |
| 231 | + RUBY |
| 232 | + end |
| 233 | + end |
| 234 | + |
| 235 | + context 'when using Rails.root in string interpolation followed by a forward slash' do |
| 236 | + it 'does not register an offense' do |
| 237 | + expect_no_offenses(<<~'RUBY') |
| 238 | + "#{Rails.root}/" |
| 239 | + RUBY |
| 240 | + end |
| 241 | + end |
| 242 | + |
143 | 243 | context 'when using Rails.root called by double quoted string' do
|
144 | 244 | it 'registers an offense' do
|
145 | 245 | expect_offense(<<~'RUBY')
|
|
526 | 626 | end
|
527 | 627 | end
|
528 | 628 |
|
| 629 | + context 'when using File.join with Rails.root and an empty string as a path' do |
| 630 | + it 'does not register an offense' do |
| 631 | + expect_no_offenses(<<~RUBY) |
| 632 | + File.join(Rails.root, "") |
| 633 | + RUBY |
| 634 | + end |
| 635 | + end |
| 636 | + |
| 637 | + context 'when using File.join with Rails.root and a single forward slash as a path' do |
| 638 | + it 'does not register an offense' do |
| 639 | + expect_no_offenses(<<~RUBY) |
| 640 | + File.join(Rails.root, "/") |
| 641 | + RUBY |
| 642 | + end |
| 643 | + end |
| 644 | + |
| 645 | + context 'when using File.join with Rails.root and a directory path ending in a slash' do |
| 646 | + it 'does not register an offense' do |
| 647 | + expect_no_offenses(<<~RUBY) |
| 648 | + File.join(Rails.root, 'app/') |
| 649 | + RUBY |
| 650 | + end |
| 651 | + end |
| 652 | + |
| 653 | + context 'when using File.join with Rails.root and multiple string paths with different trailing slash placements' do |
| 654 | + it 'does not register an offense' do |
| 655 | + expect_no_offenses(<<~RUBY) |
| 656 | + File.join(Rails.root, 'app', 'models/') |
| 657 | + RUBY |
| 658 | + |
| 659 | + expect_no_offenses(<<~RUBY) |
| 660 | + File.join(Rails.root, 'app/', 'models') |
| 661 | + RUBY |
| 662 | + |
| 663 | + expect_no_offenses(<<~RUBY) |
| 664 | + File.join(Rails.root, 'app/', 'models/') |
| 665 | + RUBY |
| 666 | + |
| 667 | + expect_no_offenses(<<~RUBY) |
| 668 | + File.join(Rails.root, 'app/', '/models') |
| 669 | + RUBY |
| 670 | + |
| 671 | + expect_no_offenses(<<~RUBY) |
| 672 | + File.join(Rails.root, '/app', 'models/') |
| 673 | + RUBY |
| 674 | + end |
| 675 | + end |
| 676 | + |
| 677 | + context 'when using File.join with Rails.root and string paths with one or more end with a trailing slash' do |
| 678 | + it 'does not register an offense' do |
| 679 | + expect_no_offenses(<<~RUBY) |
| 680 | + File.join(Rails.root, 'app/models/', 'goober') |
| 681 | + RUBY |
| 682 | + |
| 683 | + expect_no_offenses(<<~RUBY) |
| 684 | + File.join(Rails.root, 'app/models/', '/goober') |
| 685 | + RUBY |
| 686 | + |
| 687 | + expect_no_offenses(<<~RUBY) |
| 688 | + File.join(Rails.root, 'app/models', 'goober/') |
| 689 | + RUBY |
| 690 | + |
| 691 | + expect_no_offenses(<<~RUBY) |
| 692 | + File.join(Rails.root, 'app/models/', 'goober/') |
| 693 | + RUBY |
| 694 | + end |
| 695 | + end |
| 696 | + |
| 697 | + context 'when using File.join with Rails.root and an empty last argument' do |
| 698 | + it 'does not register an offense' do |
| 699 | + expect_no_offenses(<<~RUBY) |
| 700 | + File.join(Rails.root, "app", "") |
| 701 | + RUBY |
| 702 | + end |
| 703 | + end |
| 704 | + |
| 705 | + context 'when using File.join with Rails.root and a single forward slash as the last argument' do |
| 706 | + it 'does not register an offense' do |
| 707 | + expect_no_offenses(<<~RUBY) |
| 708 | + File.join(Rails.root, 'app', '/') |
| 709 | + RUBY |
| 710 | + end |
| 711 | + end |
| 712 | + |
| 713 | + context 'when using Rails.root.join with a directory ending with a slash' do |
| 714 | + it 'registers an offense' do |
| 715 | + expect_offense(<<~RUBY) |
| 716 | + Rails.root.join("app/").to_s |
| 717 | + ^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to')`. |
| 718 | + RUBY |
| 719 | + |
| 720 | + expect_correction(<<~RUBY) |
| 721 | + Rails.root.join("app", "").to_s |
| 722 | + RUBY |
| 723 | + end |
| 724 | + end |
| 725 | + |
| 726 | + context 'when using Rails.root in string interpolation followed by a forward slash' do |
| 727 | + it 'does not register an offense' do |
| 728 | + expect_no_offenses(<<~'RUBY') |
| 729 | + "#{Rails.root}/" |
| 730 | + RUBY |
| 731 | + end |
| 732 | + end |
| 733 | + |
529 | 734 | context 'when using Rails.root called by double quoted string' do
|
530 | 735 | it 'registers an offense' do
|
531 | 736 | expect_offense(<<~'RUBY')
|
|
0 commit comments