diff options
| -rw-r--r-- | lib/irb/history.rb | 4 | ||||
| -rw-r--r-- | lib/irb/init.rb | 2 | ||||
| -rw-r--r-- | test/irb/test_history.rb | 41 |
3 files changed, 46 insertions, 1 deletions
diff --git a/lib/irb/history.rb b/lib/irb/history.rb index 25fa71b9c3..0beff15539 100644 --- a/lib/irb/history.rb +++ b/lib/irb/history.rb @@ -2,9 +2,13 @@ require "pathname" 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 diff --git a/lib/irb/init.rb b/lib/irb/init.rb index d474bd41d6..b41536e61a 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -93,7 +93,7 @@ module IRB # :nodoc: @CONF[:VERBOSE] = nil @CONF[:EVAL_HISTORY] = nil - @CONF[:SAVE_HISTORY] = 1000 + @CONF[:SAVE_HISTORY] = History::DEFAULT_ENTRY_LIMIT @CONF[:BACK_TRACE_LIMIT] = 16 diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 021bb682c1..0171bb0eca 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -279,6 +279,47 @@ module TestIRB 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 "" |
