Sha256: 3e07082378ea2f3d2f062f2fa6a038f2a72181be0f11d1c020159f06257ad321

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "Configliere::Prompt" do
  before do
    @config = Configliere::Param.new
    @config.use :prompt
    @config.define :underpants, :description => 'boxers or briefs'
  end

  describe 'when the value is already set, #prompt_for' do
    it 'returns the value' do
      @config[:underpants] = :boxers
      @config.prompt_for(:underpants).should == :boxers
    end
    it 'returns the value even if nil' do
      @config[:underpants] = nil
      @config.prompt_for(:underpants).should == nil
    end
    it 'returns the value even if nil' do
      @config[:underpants] = false
      @config.prompt_for(:underpants).should == false
    end
  end

  describe 'when prompting, #prompt_for' do
    it 'prompts for a value if missing' do
      @config.should_receive(:ask).with("surprise_param? ")
      @config.prompt_for(:surprise_param)
    end
    it 'uses an explicit hint' do
      @config.should_receive(:ask).with("underpants (wearing any)? ")
      @config.prompt_for(:underpants, "wearing any")
    end
    it 'uses the description as hint if none given' do
      @config.should_receive(:ask).with("underpants (boxers or briefs)? ")
      @config.prompt_for(:underpants)
    end
  end

  describe '#resolve!' do
    it 'calls super and returns self' do
      Configliere::ParamParent.class_eval do def resolve!() dummy ; end ; end
      @config.should_receive(:dummy)
      @config.resolve!.should equal(@config)
      Configliere::ParamParent.class_eval do def resolve!() self ; end ; end
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
configliere-0.4.14 spec/configliere/prompt_spec.rb
configliere-0.4.13 spec/configliere/prompt_spec.rb
configliere-0.4.12 spec/configliere/prompt_spec.rb
configliere-0.4.11 spec/configliere/prompt_spec.rb
configliere-0.4.10 spec/configliere/prompt_spec.rb
configliere-0.4.8 spec/configliere/prompt_spec.rb
configliere-0.4.7 spec/configliere/prompt_spec.rb
configliere-0.4.6 spec/configliere/prompt_spec.rb
configliere-0.4.5 spec/configliere/prompt_spec.rb