Sha256: 363b77afefe1ca7118f71a63cd4c253684355dead9e4e7eee5b741d88c8bad7e

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

RSpec.describe TTY::ProgressBar, '#current=' do
  let(:output) { StringIO.new('', 'w+') }

  it "allows to go back" do
    progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
    3.times { progress.advance }
    progress.current = 5
    expect(progress.current).to eq(5)
    output.rewind
    expect(output.read).to eq([
      "\e[1G[=         ]",
      "\e[1G[==        ]",
      "\e[1G[===       ]",
      "\e[1G[=====     ]"
    ].join)
    progress.current = 0
    expect(progress.current).to eq(0)
  end

  it "doesn't allow to go over total" do
    progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
    progress.current = 12
    expect(progress.current).to eq(10)
    output.rewind
    expect(output.read).to eq("\e[1G[==========]\n")
  end

  it "doesn't allow to go below 0" do
    progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
    progress.current = -1
    expect(progress.current).to eq(0)
  end

  it "cannot backtrack on finished" do
    progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
    progress.current = 10
    expect(progress.current).to eq(10)
    progress.current = 5
    expect(progress.current).to eq(10)
    output.rewind
    expect(output.read).to eq("\e[1G[==========]\n")
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tty-progressbar-0.17.0 spec/unit/set_current_spec.rb
tty-progressbar-0.16.0 spec/unit/set_current_spec.rb
tty-progressbar-0.15.1 spec/unit/set_current_spec.rb
tty-progressbar-0.15.0 spec/unit/set_current_spec.rb
tty-progressbar-0.14.0 spec/unit/set_current_spec.rb
tty-progressbar-0.13.0 spec/unit/set_current_spec.rb