Sha256: 8e22112e037c714716a2fe1cd47c34429b774c8e61c4555817182ff971ca4714

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

require "#{File.dirname __FILE__}/../ruby_ext_spec_helper"
require "ruby_ext/prepare_arguments"

describe "Prepare Arguments" do
  
  it "basic parsing" do
    ArgumentsParser.register :m, [:object, :array, :hash]
    ArgumentsParser.parse_arguments_for(:m, :o, 1).should == [:o, [1], {}]
  end
  
  it "basic method wrapping" do
    class BMWTest
      def add content, options
        :ok
      end
      prepare_arguments_for :add, {:type => :object, :required => true}, :hash
    end
    
    BMWTest.new.add('text').should == :ok
  end
  
  it "except_last_hash for array" do
    ArgumentsParser.register :m, [{:type => :array, :range => :except_last_hash}, :hash]
    ArgumentsParser.parse_arguments_for(:m, 1, 2, 3, :a => :b).should == [[1, 2, 3], {:a => :b}]
    ArgumentsParser.parse_arguments_for(:m, :a => :b).should == [[], {:a => :b}]
    ArgumentsParser.parse_arguments_for(:m, 1, 2, 3).should == [[1, 2, 3], {}]
  end
  
  it "except_last_hash for object" do
    ArgumentsParser.register :m, [{:type => :object, :range => :except_last_hash}, :hash]
    ArgumentsParser.parse_arguments_for(:m, 1, :a => :b).should == [1, {:a => :b}]
    ArgumentsParser.parse_arguments_for(:m, :a => :b).should == [nil, {:a => :b}]
    ArgumentsParser.parse_arguments_for(:m, 1).should == [1, {}]
  end
  
  it "default value" do
    ArgumentsParser.register :m, [{:type => :object, :default => ""}]
    ArgumentsParser.parse_arguments_for(:m).should == [""]
  end
  
  it "string" do
    ArgumentsParser.register :m, [:string]
    ArgumentsParser.parse_arguments_for(:m).should == [""]
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-ext-0.4.1 spec/ruby_ext/prepare_arguments_spec.rb
ruby-ext-0.4.0 spec/ruby_ext/prepare_arguments_spec.rb