Sha256: 6bbae369d9ba9a4e2eba82db1592dcaa8cb68435c485bdfcd3b079a9c98427a8

Contents?: true

Size: 865 Bytes

Versions: 5

Compression:

Stored size: 865 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'spec_helper'

describe TTY::Shell::Reader, '#getc' do
  let(:instance) { described_class.new(shell) }

  let(:input)  { StringIO.new }
  let(:output) { StringIO.new }
  let(:shell) { TTY::Shell.new(input, output) }
  let(:mask) { '*'}

  subject(:reader) { instance.getc mask }

  it 'masks characters' do
    input << "password\n"
    input.rewind
    expect(reader).to eql "password"
    expect(output.string).to eql("********")
  end

  context "without mask" do
    let(:mask) { }

    it 'masks characters' do
      input << "password\n"
      input.rewind
      expect(reader).to eql "password"
      expect(output.string).to eql("password")
    end

  end

  it 'deletes characters when backspace pressed' do
    input << "\b\b"
    input.rewind
    expect(reader).to eql ''
    expect(output.string).to eql('')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/shell/reader/getc_spec.rb
tty-0.0.10 spec/tty/shell/reader/getc_spec.rb
tty-0.0.9 spec/tty/shell/reader/getc_spec.rb
tty-0.0.8 spec/tty/shell/reader/getc_spec.rb
tty-0.0.7 spec/tty/shell/reader/getc_spec.rb