Skip to content

Commit

Permalink
IRB.conf[:SAVE_HISTORY] should handle boolean values (#1062)
Browse files Browse the repository at this point in the history
Although not documented, `IRB.conf[:SAVE_HISTORY]` used to accept boolean,
which now causes `NoMethodError` when used.

This commit changes the behavior to accept boolean values and
adds tests for the behavior.
  • Loading branch information
st0012 authored Jan 11, 2025
1 parent 4d74d39 commit 8b1a07b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/irb/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

module IRB
module History
DEFAULT_ENTRY_LIMIT = 1000

class << self
# Integer representation of <code>IRB.conf[:HISTORY_FILE]</code>.
def save_history
return 0 if IRB.conf[:SAVE_HISTORY] == false
return DEFAULT_ENTRY_LIMIT if IRB.conf[:SAVE_HISTORY] == true
IRB.conf[:SAVE_HISTORY].to_i
end

Expand Down
2 changes: 1 addition & 1 deletion lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def IRB.init_config(ap_path)
@CONF[:VERBOSE] = nil

@CONF[:EVAL_HISTORY] = nil
@CONF[:SAVE_HISTORY] = 1000
@CONF[:SAVE_HISTORY] = History::DEFAULT_ENTRY_LIMIT

@CONF[:BACK_TRACE_LIMIT] = 16

Expand Down
41 changes: 41 additions & 0 deletions test/irb/test_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,47 @@ def with_temp_stdio
end

class IRBHistoryIntegrationTest < IntegrationTestCase
def test_history_saving_can_be_disabled_with_false
write_history ""
write_rc <<~RUBY
IRB.conf[:SAVE_HISTORY] = false
RUBY

write_ruby <<~'RUBY'
binding.irb
RUBY

output = run_ruby_file do
type "puts 'foo' + 'bar'"
type "exit"
end

assert_include(output, "foobar")
assert_equal "", @history_file.open.read
end

def test_history_saving_accepts_true
write_history ""
write_rc <<~RUBY
IRB.conf[:SAVE_HISTORY] = true
RUBY

write_ruby <<~'RUBY'
binding.irb
RUBY

output = run_ruby_file do
type "puts 'foo' + 'bar'"
type "exit"
end

assert_include(output, "foobar")
assert_equal <<~HISTORY, @history_file.open.read
puts 'foo' + 'bar'
exit
HISTORY
end

def test_history_saving_with_debug
write_history ""

Expand Down

0 comments on commit 8b1a07b

Please sign in to comment.