|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe RuboCop::Cop::Rails::StripHeredoc, :config do |
| 4 | + context 'Ruby <= 2.2', :ruby22 do |
| 5 | + it 'does not register an offense when using `strip_heredoc`' do |
| 6 | + expect_no_offenses(<<~RUBY) |
| 7 | + <<-EOS.strip_heredoc |
| 8 | + some text |
| 9 | + EOS |
| 10 | + RUBY |
| 11 | + end |
| 12 | + end |
| 13 | + |
| 14 | + context 'Ruby >= 2.3', :ruby23 do |
| 15 | + it 'registers an offense when using `strip_heredoc` with `<<`' do |
| 16 | + expect_offense(<<~RUBY) |
| 17 | + <<EOS.strip_heredoc |
| 18 | + ^^^^^^^^^^^^^^^^^^^ Use squiggly heredoc (`<<~`) instead of `strip_heredoc`. |
| 19 | + some text |
| 20 | + EOS |
| 21 | + RUBY |
| 22 | + |
| 23 | + expect_correction(<<~RUBY) |
| 24 | + <<~EOS |
| 25 | + some text |
| 26 | + EOS |
| 27 | + RUBY |
| 28 | + end |
| 29 | + |
| 30 | + it 'registers an offense when using `strip_heredoc` with `<<-`' do |
| 31 | + expect_offense(<<~RUBY) |
| 32 | + <<-EOS.strip_heredoc |
| 33 | + ^^^^^^^^^^^^^^^^^^^^ Use squiggly heredoc (`<<~`) instead of `strip_heredoc`. |
| 34 | + some text |
| 35 | + EOS |
| 36 | + RUBY |
| 37 | + |
| 38 | + expect_correction(<<~RUBY) |
| 39 | + <<~EOS |
| 40 | + some text |
| 41 | + EOS |
| 42 | + RUBY |
| 43 | + end |
| 44 | + |
| 45 | + it 'registers an offense when using `strip_heredoc.do_something`' do |
| 46 | + expect_offense(<<~RUBY) |
| 47 | + <<-EOS.strip_heredoc.do_something |
| 48 | + ^^^^^^^^^^^^^^^^^^^^ Use squiggly heredoc (`<<~`) instead of `strip_heredoc`. |
| 49 | + some text |
| 50 | + EOS |
| 51 | + RUBY |
| 52 | + |
| 53 | + expect_correction(<<~RUBY) |
| 54 | + <<~EOS.do_something |
| 55 | + some text |
| 56 | + EOS |
| 57 | + RUBY |
| 58 | + end |
| 59 | + |
| 60 | + it 'registers an offense when using `strip_heredoc` with multiline text' do |
| 61 | + expect_offense(<<~RUBY) |
| 62 | + <<-EOS.strip_heredoc |
| 63 | + ^^^^^^^^^^^^^^^^^^^^ Use squiggly heredoc (`<<~`) instead of `strip_heredoc`. |
| 64 | + some text |
| 65 | + some text |
| 66 | + EOS |
| 67 | + RUBY |
| 68 | + |
| 69 | + expect_correction(<<~RUBY) |
| 70 | + <<~EOS |
| 71 | + some text |
| 72 | + some text |
| 73 | + EOS |
| 74 | + RUBY |
| 75 | + end |
| 76 | + |
| 77 | + it 'does not register an offense when using squiggly heredoc' do |
| 78 | + expect_no_offenses(<<~RUBY) |
| 79 | + <<~EOS |
| 80 | + some text |
| 81 | + EOS |
| 82 | + RUBY |
| 83 | + end |
| 84 | + |
| 85 | + it 'does not register an offense when using `do_something.strip_heredoc`' do |
| 86 | + expect_no_offenses(<<~RUBY) |
| 87 | + <<-EOS.do_something.strip_heredoc |
| 88 | + some text |
| 89 | + EOS |
| 90 | + RUBY |
| 91 | + end |
| 92 | + |
| 93 | + it 'does not register an offense when using `strip_heredoc` without receiver' do |
| 94 | + expect_no_offenses(<<~RUBY) |
| 95 | + strip_heredoc |
| 96 | + RUBY |
| 97 | + end |
| 98 | + end |
| 99 | +end |
0 commit comments