1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# frozen_string_literal: true
require 'spec_helper'
require 'tempfile'
RSpec.describe Gitlab::Shell::History do
context 'when saving to a file' do
before do
@file = Tempfile.new('.gitlab_shell_history')
@history = described_class.new(file_path: @file.path)
end
after { @file.close(true) }
it 'saves the lines' do
@history << 'party on, dudes'
@history << 'be excellent to each other'
@history.save
expect(File.read(@file.path))
.to eq("party on, dudes\nbe excellent to each other\n")
end
it 'has the lines' do
@history << 'party on, dudes'
@history << 'be excellent to each other'
expect(@history.lines)
.to eq(['party on, dudes', 'be excellent to each other'])
end
it 'limits the lines to GITLAB_HISTFILESIZE' do
ENV['GITLAB_HISTFILESIZE'] = '2'
@history << 'bogus'
@history << 'party on, dudes'
@history << 'be excellent to each other'
@history.save
expect(@history.lines)
.to eq(['party on, dudes', 'be excellent to each other'])
expect(File.read(@file.path))
.to eq("party on, dudes\nbe excellent to each other\n")
end
end
context 'when loading a file' do
before do
@file = load_fixture('shell_history.txt')
@history = described_class.new(file_path: @file.path)
end
it 'has the lines' do
@history.load
expect(@history.lines)
.to eq(['party on, dudes', 'be excellent to each other'])
end
end
end
|