Sha256: 99e50fa8d87e56be0f5ba10c2e6bf33cc1f0fdf8f01adf3c0453d24bee70ee6c

Contents?: true

Size: 582 Bytes

Versions: 6

Compression:

Stored size: 582 Bytes

Contents

RSpec.describe TTY::ProgressBar, 'custom formatter' do
  let(:output) { StringIO.new('', 'w+') }

  it "allows for custom tag" do
    progress = TTY::ProgressBar.new(":hi", output: output, total: 10)

    stub_const("HiFormatter", Class.new do
      def initialize(progress)
        @progress = progress
      end

      def matches?(value)
        value.to_s =~ /:hi/
      end

      def format(value)
        value.gsub(/:hi/, "Hello")
      end
    end)

    progress.use(HiFormatter)
    progress.advance
    output.rewind
    expect(output.read).to eq("\e[1GHello")
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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