Sha256: 6b97c1a79070c769698156b5c51dfe2aa01f64a7755f93b257c7fce5b901f6f5

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

RSpec.describe TTY::Spinner, "#log" do
  let(:output) { StringIO.new("", "w+") }

  it "logs a message above a spinner" do
    spinner = TTY::Spinner.new(output: output)

    2.times {
      spinner.log "foo\nbar"
      spinner.spin
    }
    output.rewind

    expect(output.read).to eq([
      "\e[2K\e[1Gfoo\n",
      "\e[2K\e[1Gbar\n",
      "\e[1G|",
      "\e[1G|",
      "\e[2K\e[1Gfoo\n",
      "\e[2K\e[1Gbar\n",
      "\e[1G/",
      "\e[1G/"
    ].join)
  end

  it "logs a message ending with a newline above a spinner" do
    spinner = TTY::Spinner.new(output: output)

    2.times {
      spinner.log "foo\n"
      spinner.spin
    }
    output.rewind

    expect(output.read).to eq([
      "\e[2K\e[1Gfoo\n",
      "\e[1G|",
      "\e[1G|",
      "\e[2K\e[1Gfoo\n",
      "\e[1G/",
      "\e[1G/"
    ].join)
  end

  it "logs message under a spinner when done" do
    spinner = TTY::Spinner.new(output: output)
    2.times { spinner.spin }
    spinner.stop

    spinner.log "foo\nbar"

    output.rewind
    expect(output.read).to eq([
      "\e[1G|",
      "\e[1G/",
      "\e[0m\e[2K\e[1G/\n",
      "\e[2K\e[1Gfoo\n",
      "\e[2K\e[1Gbar\n"
    ].join)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
planter-cli-3.0.7 lib/tty-spinner/spec/unit/log_spec.rb
planter-cli-3.0.5 lib/tty-spinner/spec/unit/log_spec.rb
planter-cli-3.0.4 lib/tty-spinner/spec/unit/log_spec.rb
planter-cli-3.0.3 lib/tty-spinner/spec/unit/log_spec.rb
planter-cli-3.0.2 lib/tty-spinner/spec/unit/log_spec.rb