Sha256: 3ca1092275044a7db21353ac579a3acd02dcf641a2265cecc61dd83db7ed2c39

Contents?: true

Size: 914 Bytes

Versions: 6

Compression:

Stored size: 914 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) }

  subject(:reader) { instance.getc mask }

  context 'with mask' do
    let(:mask) { '*'}

    it 'masks characters' do
      input << "password\n"
      input.rewind
      expect(reader).to eql "password"
      expect(output.string).to eql("********")
    end
  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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tty-0.2.1 spec/tty/shell/reader/getc_spec.rb
tty-0.2.0 spec/tty/shell/reader/getc_spec.rb
tty-0.1.3 spec/tty/shell/reader/getc_spec.rb
tty-0.1.2 spec/tty/shell/reader/getc_spec.rb
tty-0.1.1 spec/tty/shell/reader/getc_spec.rb
tty-0.1.0 spec/tty/shell/reader/getc_spec.rb