Sha256: ab463dd71d2cbb073929055d6427ccf5259287dc932ed1cf7ad89d844a8c2bbc

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

require 'rib/test'
require 'rib/core/squeeze_history'

shared :squeeze_history do
  should 'after_loop saves squeezed history' do
    @shell.history.push(*@input)
    @shell.after_loop
    File.read(@history).should.eq %w[foo bar foo bar].join("\n") + "\n"
  end

  should 'loop_once squeeze history' do
    times = @input.size
    stub(@shell).get_input{ (@shell.history << "'#{@input.shift}'").last }
    stub(@shell).print_result{}.with_any_args
    times.times{ @shell.loop_once }
    @shell.history.to_a.should.eq %w[foo bar foo bar].map{ |i| "'#{i}'" }
  end

  should 'be disabled if disabled' do
    Rib::SqueezeHistory.disable do
      times = @input.size
      input = @input.dup
      stub(@shell).get_input{ (@shell.history << "'#{@input.shift}'").last }
      stub(@shell).print_result{}.with_any_args
      times.times{ @shell.loop_once }
      @shell.history.to_a.should.eq input.map{ |i| "'#{i}'" }
    end
  end
end

describe Rib::SqueezeHistory do
  behaves_like :rib

  before do
    @history = "/tmp/test_rib_#{rand}"
    @shell   = Rib::Shell.new(:history_file => @history).before_loop
    @input   = %w[foo bar bar foo bar]
    @shell.history.clear
  end

  after do
    FileUtils.rm_f(@history)
  end

  test_for Rib::History, Rib::SqueezeHistory do
    behaves_like :squeeze_history
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rib-1.2.5 test/core/test_squeeze_history.rb
rib-1.2.4 test/core/test_squeeze_history.rb
rib-1.2.3 test/core/test_squeeze_history.rb
rib-1.2.2 test/core/test_squeeze_history.rb
rib-1.2.1 test/core/test_squeeze_history.rb
rib-1.2.0 test/core/test_squeeze_history.rb