File: edit_test.rb

package info (click to toggle)
ruby-byebug 11.1.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,252 kB
  • sloc: ruby: 8,835; ansic: 1,662; sh: 6; makefile: 4
file content (69 lines) | stat: -rw-r--r-- 1,798 bytes parent folder | download | duplicates (3)
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
# frozen_string_literal: true

require "test_helper"

module Byebug
  #
  # Tests file editing from within Byebug.
  #
  class EditTest < TestCase
    def test_edit_opens_current_file_in_current_line_in_configured_editor
      with_env("EDITOR", "edi") do
        assert_calls(Kernel, :system, "edi +4 #{example_path}") do
          enter "edit"
          debug_code(minimal_program)
        end
      end
    end

    def test_edit_calls_vim_if_no_editor_environment_variable_is_set
      with_env("EDITOR", nil) do
        assert_calls(Kernel, :system, "vim +4 #{example_path}") do
          enter "edit"
          debug_code(minimal_program)
        end
      end
    end

    def test_edit_opens_configured_editor_at_specific_line_and_file
      with_env("EDITOR", "edi") do
        assert_calls(Kernel, :system, "edi +3 #{readme_path}") do
          enter "edit README.md:3"
          debug_code(minimal_program)
        end
      end
    end

    def test_edit_shows_an_error_if_specified_file_does_not_exist
      file = File.expand_path("no_such_file")
      enter "edit no_such_file:6"
      debug_code(minimal_program)

      check_error_includes "File #{file} does not exist."
    end

    def test_edit_shows_an_error_if_the_specified_file_is_not_readable
      File.stub(:readable?, false) do
        enter "edit README.md:6"
        debug_code(minimal_program)

        check_error_includes "File #{readme_path} is not readable."
      end
    end

    def test_edit_accepts_no_line_specification
      with_env("EDITOR", "edi") do
        assert_calls(Kernel, :system, "edi #{readme_path}") do
          enter "edit README.md"
          debug_code(minimal_program)
        end
      end
    end

    private

    def readme_path
      File.expand_path("README.md")
    end
  end
end