116 lines
2 KiB
Ruby
116 lines
2 KiB
Ruby
require 'progress-bar'
|
|
|
|
[ProgressBar::Console, ProgressBar::KDE, ProgressBar::KDialog].each do |klass|
|
|
describe klass do
|
|
before do
|
|
@bar = klass.new 100, 'starting...', title: 'rspec',
|
|
outfd: STDERR, errfd: STDERR, # ProgressBar::Console
|
|
app_name: 'rspec', app_icon_name: '' # ProgressBar::KDE
|
|
@bar.start
|
|
end
|
|
|
|
after do
|
|
@bar.finish
|
|
end
|
|
|
|
it 'start' do
|
|
end
|
|
|
|
describe '#max' do
|
|
it 'sets maximum of 5' do
|
|
@bar.max = 5
|
|
expect(@bar.max).to eql(5)
|
|
end
|
|
|
|
it 'sets maximum of 100' do
|
|
@bar.max = 100
|
|
expect(@bar.max).to eql(100)
|
|
end
|
|
end
|
|
|
|
it 'is possible to use, if outfd&errfd are a tty' do
|
|
expect(@bar.possible?).to eql(true)
|
|
end
|
|
|
|
describe '#i=' do
|
|
it 'has 20 progress' do
|
|
@bar.i = 20
|
|
@bar.text = "test: i=20"
|
|
sleep 1
|
|
end
|
|
|
|
it 'has 3 progress of 6' do
|
|
@bar.max = 6
|
|
@bar.text = "test: max=6"
|
|
sleep 1
|
|
@bar.i = 3
|
|
@bar.text = "test: max=6, i=3"
|
|
sleep 1
|
|
expect(@bar.done_rel).to eql(50.0)
|
|
sleep 1
|
|
end
|
|
end
|
|
|
|
describe '#increment!' do
|
|
it 'increases progress' do
|
|
sleep 1
|
|
@bar.increment!
|
|
@bar.text = "test: (i+=1) = 1"
|
|
sleep 1
|
|
expect(@bar.i).to eql(1)
|
|
sleep 1
|
|
end
|
|
end
|
|
|
|
it 'displays text' do
|
|
@bar.text = 'processing...'
|
|
end
|
|
|
|
it 'displays an error' do
|
|
sleep 1
|
|
@bar.error 'failed :('
|
|
sleep 1
|
|
@bar.text = '^^ failed? ^^'
|
|
sleep 1
|
|
end
|
|
end
|
|
end
|
|
|
|
__END__
|
|
describe ProgressBar::KDE do
|
|
before do
|
|
@bar = ProgressBar::KDE.new 100, 'starting...', title: 'rspec', app_name: 'rspec'
|
|
@bar.start
|
|
end
|
|
|
|
it 'is possible, if XDG_DESKTOP is KDE' do
|
|
expect(@bar.possible?).to eql(true)
|
|
end
|
|
|
|
it 'start' do
|
|
@bar.start
|
|
end
|
|
|
|
it 'finish' do
|
|
@bar.finish
|
|
end
|
|
end
|
|
|
|
describe ProgressBar::KDialog do
|
|
before do
|
|
@bar = ProgressBar::KDE.new 100, 'starting...', title: 'rspec'
|
|
@bar.start
|
|
end
|
|
|
|
it 'is possible to use, if kdialog found' do
|
|
expect(@bar.possible?).to eql(true)
|
|
end
|
|
|
|
it 'start' do
|
|
@bar.start
|
|
end
|
|
|
|
it 'finish' do
|
|
@bar.finish
|
|
end
|
|
end
|