|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative "../spec_helper.rb" |
| 4 | + |
| 5 | +module SyntaxErrorSearch |
| 6 | + RSpec.describe TrailingSlashJoin do |
| 7 | + |
| 8 | + it "formats output" do |
| 9 | + code_lines = code_line_array(<<~'EOM') |
| 10 | + context "timezones workaround" do |
| 11 | + it "should receive a time in UTC format and return the time with the"\ |
| 12 | + "office's UTC offset substracted from it" do |
| 13 | + travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do |
| 14 | + office = build(:office) |
| 15 | + end |
| 16 | + end |
| 17 | + end |
| 18 | + EOM |
| 19 | + |
| 20 | + out_code_lines = TrailingSlashJoin.new(code_lines: code_lines).call |
| 21 | + expect( |
| 22 | + DisplayCodeWithLineNumbers.new( |
| 23 | + lines: out_code_lines.select(&:visible?) |
| 24 | + ).call |
| 25 | + ).to eq(<<~'EOM'.indent(2)) |
| 26 | + 1 context "timezones workaround" do |
| 27 | + 2 it "should receive a time in UTC format and return the time with the"\ |
| 28 | + 3 "office's UTC offset substracted from it" do |
| 29 | + 4 travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do |
| 30 | + 5 office = build(:office) |
| 31 | + 6 end |
| 32 | + 7 end |
| 33 | + 8 end |
| 34 | + EOM |
| 35 | + |
| 36 | + expect( |
| 37 | + DisplayCodeWithLineNumbers.new( |
| 38 | + lines: out_code_lines.select(&:visible?), |
| 39 | + highlight_lines: out_code_lines[1] |
| 40 | + ).call |
| 41 | + ).to eq(<<~'EOM') |
| 42 | + 1 context "timezones workaround" do |
| 43 | + ❯ 2 it "should receive a time in UTC format and return the time with the"\ |
| 44 | + ❯ 3 "office's UTC offset substracted from it" do |
| 45 | + 4 travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do |
| 46 | + 5 office = build(:office) |
| 47 | + 6 end |
| 48 | + 7 end |
| 49 | + 8 end |
| 50 | + EOM |
| 51 | + end |
| 52 | + |
| 53 | + it "trailing slash" do |
| 54 | + code_lines = code_line_array(<<~'EOM') |
| 55 | + it "trailing s" \ |
| 56 | + "lash" do |
| 57 | + EOM |
| 58 | + |
| 59 | + out_code_lines = TrailingSlashJoin.new(code_lines: code_lines).call |
| 60 | + |
| 61 | + expect(code_lines[0]).to_not be_hidden |
| 62 | + expect(code_lines[1]).to be_hidden |
| 63 | + |
| 64 | + expect( |
| 65 | + out_code_lines.join |
| 66 | + ).to eq(code_lines.map(&:original).join) |
| 67 | + end |
| 68 | + |
| 69 | + it "doesn't falsely identify trailing slashes" do |
| 70 | + code_lines = code_line_array(<<~'EOM') |
| 71 | + def formatters |
| 72 | + @formatters ||= { |
| 73 | + amazing_print: ->(obj) { obj.ai + "\n" }, |
| 74 | + inspect: ->(obj) { obj.inspect + "\n" }, |
| 75 | + json: ->(obj) { obj.to_json }, |
| 76 | + marshal: ->(obj) { Marshal.dump(obj) }, |
| 77 | + none: ->(_obj) { nil }, |
| 78 | + pretty_json: ->(obj) { JSON.pretty_generate(obj) }, |
| 79 | + pretty_print: ->(obj) { obj.pretty_inspect }, |
| 80 | + puts: ->(obj) { require 'stringio'; sio = StringIO.new; sio.puts(obj); sio.string }, |
| 81 | + to_s: ->(obj) { obj.to_s + "\n" }, |
| 82 | + yaml: ->(obj) { obj.to_yaml }, |
| 83 | + } |
| 84 | + end |
| 85 | + EOM |
| 86 | + |
| 87 | + out_code_lines = TrailingSlashJoin.new(code_lines: code_lines).call |
| 88 | + expect(out_code_lines.join).to eq(code_lines.join) |
| 89 | + end |
| 90 | + end |
| 91 | +end |
0 commit comments