Skip to content

Commit

Permalink
Introduce write_rc test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Aug 21, 2023
1 parent abcf12a commit 986c7ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
17 changes: 16 additions & 1 deletion test/irb/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ def setup
end

@envs = {}
@tmpfiles = []
end

def teardown
@tmpfiles.each do |tmpfile|
File.unlink(tmpfile)
end
end

def run_ruby_file(&block)
Expand Down Expand Up @@ -133,7 +140,6 @@ def run_ruby_file(&block)
MSG
assert_block(message) { false }
ensure
File.unlink(@ruby_file) if @ruby_file
FileUtils.remove_entry tmp_dir
end

Expand Down Expand Up @@ -180,8 +186,17 @@ def type(command)

def write_ruby(program)
@ruby_file = Tempfile.create(%w{irb- .rb})
@tmpfiles << @ruby_file
@ruby_file.write(program)
@ruby_file.close
end

def write_rc(content)
@irbrc = Tempfile.new('irbrc')
@tmpfiles << @irbrc
@irbrc.write(content)
@irbrc.close
@envs['IRBRC'] = @irbrc.path
end
end
end
7 changes: 1 addition & 6 deletions test/irb/test_debug_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,9 @@ def test_prompt_line_number_continues
end

def test_prompt_irb_name_is_kept
@irbrc = Tempfile.new('irbrc')
@irbrc.write <<~RUBY
write_rc <<~RUBY
IRB.conf[:IRB_NAME] = "foo"
RUBY
@irbrc.close
@envs['IRBRC'] = @irbrc.path

write_ruby <<~'ruby'
binding.irb
Expand All @@ -309,8 +306,6 @@ def test_prompt_irb_name_is_kept

assert_match(/foo\(main\):001> next/, output)
assert_match(/foo:rdbg\(main\):002> continue/, output)
ensure
@irbrc&.unlink
end

def test_irb_commands_are_available_after_moving_around_with_the_debugger
Expand Down
5 changes: 1 addition & 4 deletions test/irb/test_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,9 @@ def write_history(history)
@history_file = Tempfile.new('irb_history')
@history_file.write(history)
@history_file.close
@irbrc = Tempfile.new('irbrc')
@irbrc.write <<~RUBY
write_rc <<~RUBY
IRB.conf[:HISTORY_FILE] = "#{@history_file.path}"
RUBY
@irbrc.close
@envs['IRBRC'] = @irbrc.path
end
end
end

0 comments on commit 986c7ca

Please sign in to comment.