Sha256: 118de7e7d5105e024f28bcccede768719e09d6064ed51b9005f848cea58b6042

Contents?: true

Size: 1.65 KB

Versions: 21

Compression:

Stored size: 1.65 KB

Contents

require 'rib/test'
require 'rib/core/history'

shared :history do
  should '#after_loop save history' do
    inputs = %w[blih blah]
    # TODO: history.replace(input) is MRI 1.9+
    clear_history(@shell.history)
    @shell.history.push(*inputs)

    @shell.after_loop
    File.read(@history_file).should.eq "#{inputs.join("\n")}\n"
  end

  should '#before_loop load previous history' do
    File.open(@history_file, 'w'){ |f| f.write "check\nthe\nmike" }
    @shell.before_loop
    @shell.history.to_a.should.eq %w[check the mike]
  end

  should '#before_loop have empty history if no history file exists' do
    @shell.before_loop
    @shell.history.to_a.should.eq []
  end

  should '#read_history be accessible to plugins in #before_loop' do
    mod = Module.new do
      def read_history
        config[:history] = ['pong_read_history']
      end
    end
    shell = Rib::Shell.dup
    shell.use(mod)
    shell.new.before_loop.history.should.eq ['pong_read_history']
  end

  should '#write_history be accessible to plugins in #after_loop' do
    mod = Module.new do
      def write_history
        config[:history] = ['pong_write_history']
      end
    end
    shell = Rib::Shell.dup
    shell.use(mod)
    shell.new.before_loop.after_loop.history.should.eq ['pong_write_history']
  end
end

describe Rib::History do
  behaves_like :rib

  before do
    if readline?
      clear_history(::Readline::HISTORY)
      stub_readline
    end
    @history_file = "/tmp/test_rib_#{rand}"
    @shell        = Rib::Shell.new(:history_file => @history_file).before_loop
  end

  after do
    FileUtils.rm_f(@history_file)
  end

  test_for Rib::History do
    behaves_like :history
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rib-1.1.6 test/core/test_history.rb
rib-1.1.5 test/core/test_history.rb
rib-1.1.4 test/core/test_history.rb
rib-1.1.3 test/core/test_history.rb
rib-1.1.2 test/core/test_history.rb
rib-1.1.1 test/core/test_history.rb
rib-1.1.0 test/core/test_history.rb
rib-1.0.5 test/core/test_history.rb
rib-1.0.4 test/core/test_history.rb
rib-1.0.3 test/core/test_history.rb
rib-1.0.2 test/core/test_history.rb
rib-1.0.1 test/core/test_history.rb
rib-1.0.0 test/core/test_history.rb
rib-0.9.9 test/core/test_history.rb
rib-0.9.5 test/core/test_history.rb
rib-0.9.5.pre.1 test/core/test_history.rb
rib-0.9.5.pre.0 test/core/test_history.rb
rib-0.9.4 test/core/test_history.rb
rib-0.9.3 test/core/test_history.rb
rib-0.9.2 test/core/test_history.rb