summaryrefslogtreecommitdiff
path: root/spec/commands/wtf_spec.rb
blob: ace8cbf34f94d0e6db4ad4e22194666d9f3e2185 (plain)
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
# frozen_string_literal: true

describe "wtf?!" do
  let(:tester) do
    pry_tester do
      def last_exception=(exception)
        @pry.last_exception = exception
      end

      def last_exception
        @pry.last_exception
      end
    end
  end

  it "unwinds nested exceptions" do
    if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0.0')
      skip('Exception#cause is not supported')
    end

    begin
      begin
        begin
          raise 'inner'
        rescue RuntimeError
          raise 'outer'
        end
      end
    rescue RuntimeError => ex
      tester.last_exception = ex
    end

    expect(tester.eval('wtf -v')).to match(/
      Exception:\sRuntimeError:\souter
      .+
      Caused\sby:\sRuntimeError:\sinner
    /xm)
  end
end