Skip to content

Commit

Permalink
Add edit command testcase when irb_path does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Feb 12, 2024
1 parent 902727f commit 2cd06f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/irb/cmd/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ def transform_args(args)
def execute(*args)
path = args.first

if path.nil? && (irb_path = @irb_context.irb_path)
path = irb_path
end

if !File.exist?(path)
if path.nil?
path = @irb_context.irb_path
elsif !File.exist?(path)
source =
begin
SourceFinder.new(@irb_context).find_source(path)
Expand All @@ -39,12 +37,14 @@ def execute(*args)

if source&.file_exist? && !source.binary_file?
path = source.file
else
puts "Can not find file: #{path}"
return
end
end

unless File.exist?(path)
puts "Can not find file: #{path}"
return
end

if editor = (ENV['VISUAL'] || ENV['EDITOR'])
puts "command: '#{editor}'"
puts " path: #{path}"
Expand Down
10 changes: 10 additions & 0 deletions test/irb/test_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,16 @@ def test_edit_without_arg
assert_match("command: ': code'", out)
end

def test_edit_without_arg_and_non_existing_irb_path
out, err = execute_lines(
"edit",
irb_path: '/path/to/file.rb(irb)'
)

assert_empty err
assert_match(/Can not find file: \/path\/to\/file\.rb\(irb\)/, out)
end

def test_edit_with_path
out, err = execute_lines(
"edit #{__FILE__}"
Expand Down

0 comments on commit 2cd06f8

Please sign in to comment.