summaryrefslogtreecommitdiff
path: root/test/irb/command/test_command_aliasing.rb
blob: 4ecc88c0aad7d6656931d17dac522bd6dbc26b3f (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
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

require "tempfile"
require_relative "../helper"

module TestIRB
  class CommandAliasingTest < IntegrationTestCase
    def setup
      super
      write_rc <<~RUBY
        IRB.conf[:COMMAND_ALIASES] = {
          :c => :conf, # alias to helper method
          :f => :foo
        }
      RUBY

      write_ruby <<~'RUBY'
        binding.irb
      RUBY
    end

    def test_aliasing_to_helper_method_triggers_warning
      out = run_ruby_file do
        type "c"
        type "exit"
      end
      assert_include(out, "Using command alias `c` for helper method `conf` is not supported.")
      assert_not_include(out, "Maybe IRB bug!")
    end

    def test_alias_to_non_existent_command_triggers_warning
      message = "You're trying to use command alias `f` for command `foo`, but `foo` does not exist."
      out = run_ruby_file do
        type "f"
        type "exit"
      end
      assert_include(out, message)
      assert_not_include(out, "Maybe IRB bug!")

      # Local variables take precedence over command aliases
      out = run_ruby_file do
        type "f = 123"
        type "f"
        type "exit"
      end
      assert_not_include(out, message)
      assert_not_include(out, "Maybe IRB bug!")
    end
  end
end