File: frames_test.rb

package info (click to toggle)
ruby-pry-byebug 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 324 kB
  • sloc: ruby: 1,171; makefile: 4
file content (77 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download
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
# frozen_string_literal: true

require "test_helper"
require "stringio"

#
# Tests for pry-byebug frame commands.
#
class FramesTest < MiniTest::Spec
  let(:output) { StringIO.new }

  after { clean_remove_const(:FramesExample) }

  describe "Up command" do
    let(:input) { InputTester.new("up", "down") }

    before do
      redirect_pry_io(input, output) { load test_file("frames") }
    end

    it "shows current line" do
      _(output.string).must_match(/=> \s*8: \s*method_b/)
    end
  end

  describe "Down command" do
    let(:input) { InputTester.new("up", "down") }

    before do
      redirect_pry_io(input, output) { load test_file("frames") }
    end

    it "shows current line" do
      _(output.string).must_match(/=> \s*13: \s*end/)
    end
  end

  describe "Frame command" do
    before do
      redirect_pry_io(input, output) { load test_file("frames") }
    end

    describe "jump to frame 1" do
      let(:input) { InputTester.new("frame 1", "frame 0") }

      it "shows current line" do
        _(output.string).must_match(/=> \s*8: \s*method_b/)
      end
    end

    describe "jump to current frame" do
      let(:input) { InputTester.new("frame 0") }

      it "shows current line" do
        _(output.string).must_match(/=> \s*13: \s*end/)
      end
    end
  end

  describe "Backtrace command" do
    let(:input) { InputTester.new("backtrace") }

    before do
      @stdout, @stderr = capture_subprocess_io do
        redirect_pry_io(input) { load test_file("frames") }
      end
    end

    it "shows a backtrace" do
      frames = @stdout.split("\n")

      assert_match(/\A--> #0  FramesExample\.method_b at/, frames[0])
      assert_match(/\A    #1  FramesExample\.method_a at/, frames[1])
      assert_match(/\A    #2  <top \(required\)> at/, frames[2])
    end
  end
end