Sha256: 4ae1139c13f283f3d328edd65ad1006ddba5d1576cfecdb47dab57171b7928c4

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# encoding: utf-8

require 'spec_helper'
require 'cliprompt'
require 'cliprompt/optionset'

describe Cliprompt do
  Given(:input) { StringIO.new }
  Given(:output) { StringIO.new }
  Given { subject.setio(input, output) }

  describe '.ask' do
    Given(:question) { 'wazza?' }
    Given(:answer) { 'xxx' }
    context 'without default,' do
      When(:args) { }
      When { input.stub(:gets).and_return answer }
      Then { expect(subject.ask(question, args)).to eq answer }
      And  { expect(output.string).to eq "#{question}  " }
    end
    context 'with a default,' do
      When(:default) { 'ooo' }
      When(:args) { { default: default } }
      When { input.stub(:gets).and_return answer }
      Then { expect(subject.ask(question, args)).to eq answer }
      And  { expect(output.string).to eq "#{question} [#{default}] " }
    end
    context 'with an optionset,' do
      When(:args) { Cliprompt::Optionset.new() }
      When { input.stub(:gets).and_return answer }
      Then { expect(subject.ask(question, args)).to eq answer }
      And  { expect(output.string).to eq "#{question}  " }
    end
  end

  describe '.say' do
    Given(:msg) { "hah" }
    When { subject.say msg }
    Then { expect(output.string).to eq "#{msg}\n" }
  end

  describe '.shout' do
    Given(:msg) { "hah" }
    When { subject.shout msg }
    Then { expect(output.string).to eq "#{Paint[msg, :bold, :red ]}\n" }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cliprompt-0.0.2 spec/lib/cliprompt_spec.rb