Sha256: 18d1205d41c583abff68bc43f0653a4d671c4e7a44e2b3ae4574994a8825ea2c

Contents?: true

Size: 1.77 KB

Versions: 11

Compression:

Stored size: 1.77 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'
require File.dirname(__FILE__) + '/../../../lib/poolparty/helpers/optioner'

describe "Option Parser" do
  describe "options" do
    before(:each) do
      @op = PoolParty::Optioner.new([], {:abstract => true})
      @op.parse_options
    end
    it "should set the options as an Hash" do
      @op.options.class.should == Hash
    end
    it "should have the verbose option set to false by default" do
      @op.verbose.should == false
    end
    it "should call a method called on it that is not defined on the options if they exist" do
      @op.options.should_receive(:[]).with(:verbose).once.and_return true
      @op.verbose
    end
    it "should exit after displaying the help message" do
      hide_output do
        lambda {
          @o = PoolParty::Optioner.new(["-h"], {:parse_options => false})
          @o.should_receive(:process_options).once
          @o.parse_options
        }
      end
    end
  end
  
  describe "parse_args" do
    before(:each) do
      @op = PoolParty::Optioner.new(%w( -v -i 1 five six -x), {:abstract => true, :parse_options => false})
    end
    it "should have an array of default boolean args" do
      @op.boolean_args.sort.should == ['--debug', '-V', '-h', '-t', '-v']
    end
    it "should split ARGV into flagged and unflagged arg arrays" do
      @op.unflagged_args.sort.sort.should ==  ["five", "six"]
      @op.flagged_args.should == ["-v", "-i", "1", "-x"]
    end
  end
  
  it "should be able to take a block and set some options on the block" do
    PoolParty::Optioner.new(["-w"], {:abstract => false, :load_pools => false}) do |opts, optioner|
      opts.on('-w', '--wee')    { optioner.wee "wee" }
      opts.on('-t t', '--teatime tea')    { optioner.tea "time" }
    end.wee.should == "wee"
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
auser-poolparty-0.2.84 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-0.2.85 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-0.2.88 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-0.2.89 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-0.2.90 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-0.2.91 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-0.2.92 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-0.2.93 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-0.2.94 spec/poolparty/helpers/optioner_spec.rb
auser-poolparty-1.0.0 spec/poolparty/helpers/optioner_spec.rb
poolparty-0.2.84 spec/poolparty/helpers/optioner_spec.rb