Sha256: 4d304eb19e1656aaeb07d4291c6c1a35a8613c230c834672fcb1df6a09362336

Contents?: true

Size: 1.56 KB

Versions: 32

Compression:

Stored size: 1.56 KB

Contents

require 'tempfile'

describe HammerCLI::ShellHistory do
  before :each do
    Readline::HISTORY.clear
  end

  let :history_file do
    file = Tempfile.new('history')
    file.puts "line 1"
    file.puts "line 2"
    file.close
    file
  end

  let :new_file do
    Tempfile.new('history')
  end

  describe "loading old history" do

    it "skips loading if the file does not exist" do
      history = HammerCLI::ShellHistory.new(new_file.path)

      Readline::HISTORY.to_a.must_equal []
    end

    it "preseeds readline's history" do
      history = HammerCLI::ShellHistory.new(history_file.path)

      Readline::HISTORY.to_a.must_equal ["line 1", "line 2"]
    end
  end

  describe "saving history" do
    it "creates history file if it does not exist" do
      history = HammerCLI::ShellHistory.new(new_file.path)
      history.push("some command ")

      File.exist?(new_file.path).must_equal true
    end

    it "appends history to the given file" do
      history = HammerCLI::ShellHistory.new(new_file.path)
      history.push("some command ")
      history.push("another command ")

      new_file.read.must_equal "some command\nanother command\n"
    end

    it "appends to readline's history" do
      history = HammerCLI::ShellHistory.new(history_file.path)
      history.push("line 3")

      Readline::HISTORY.to_a.must_equal ["line 1", "line 2", "line 3"]
    end

    it "doesn't save exit command" do
      history = HammerCLI::ShellHistory.new(history_file.path)
      history.push("exit ")

      Readline::HISTORY.to_a.must_equal ["line 1", "line 2"]
    end
  end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
hammer_cli-3.5.1 test/unit/history_test.rb
hammer_cli-3.6.0 test/unit/history_test.rb
hammer_cli-3.5.0 test/unit/history_test.rb
hammer_cli-3.4.0 test/unit/history_test.rb
hammer_cli-3.3.0 test/unit/history_test.rb
hammer_cli-3.2.0 test/unit/history_test.rb
hammer_cli-3.1.1 test/unit/history_test.rb
hammer_cli-3.0.2 test/unit/history_test.rb
hammer_cli-3.1.0 test/unit/history_test.rb
hammer_cli-3.0.1 test/unit/history_test.rb
hammer_cli-3.0.0 test/unit/history_test.rb
hammer_cli-2.5.1 test/unit/history_test.rb
hammer_cli-2.5.0 test/unit/history_test.rb
hammer_cli-2.3.1 test/unit/history_test.rb
hammer_cli-2.4.0 test/unit/history_test.rb
hammer_cli-2.3.0 test/unit/history_test.rb
hammer_cli-2.2.1 test/unit/history_test.rb
hammer_cli-2.1.2 test/unit/history_test.rb
hammer_cli-2.2.0 test/unit/history_test.rb
hammer_cli-2.1.1 test/unit/history_test.rb