File: formatting_spec.rb

package info (click to toggle)
r10k 5.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,228 kB
  • sloc: ruby: 18,180; makefile: 10; sh: 1
file content (84 lines) | stat: -rw-r--r-- 2,215 bytes parent folder | download | duplicates (5)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require 'spec_helper'
require 'r10k/errors/formatting'

describe R10K::Errors::Formatting do

  describe "without a nested exception" do
    let(:exc) do
      ArgumentError.new("ArgumentError message").tap do |a|
        a.set_backtrace(%w[/backtrace/line:1 /backtrace/line:2])
      end
    end

    describe "and without a backtrace" do
      subject do
        described_class.format_exception(exc, false)
      end

      it "formats the exception with the message" do
        expect(subject).to eq("ArgumentError message")
      end
    end

    describe "and with a backtrace" do
      subject do
        described_class.format_exception(exc, true)
      end

      it "formats the exception with the message and backtrace" do
        expect(subject).to eq([
          "ArgumentError message",
          "/backtrace/line:1",
          "/backtrace/line:2",
        ].join("\n"))
      end
    end
  end

  describe "with a nested exception" do

    let(:nestee) do
      ArgumentError.new("ArgumentError message").tap do |a|
        a.set_backtrace(%w[/backtrace/line:1 /backtrace/line:2])
      end
    end

    let(:exc) do
      R10K::Error.wrap(nestee, "R10K::Error message").tap do |r|
        r.set_backtrace(%w[/another/backtrace/line:1 /another/backtrace/line:2])
      end
    end

    describe "and without a backtrace" do
      subject do
        described_class.format_exception(exc, false)
      end

      it "formats the exception with the message and original message" do
        expect(subject).to eq([
          "R10K::Error message",
          "Original exception:",
          "ArgumentError message"
        ].join("\n"))
      end
    end

    describe "and with a backtrace" do
      subject do
        described_class.format_exception(exc, true)
      end

      it "formats the exception with the message, backtrace, original message, and original backtrace" do
        expect(subject).to eq([
          "R10K::Error message",
          "/another/backtrace/line:1",
          "/another/backtrace/line:2",
          "Original exception:",
          "ArgumentError message",
          "/backtrace/line:1",
          "/backtrace/line:2",
        ].join("\n"))
      end
    end
  end
end