Sha256: 80af76d853af61199eb53b06a50d6ae28b99bf9ca58e5764ea04d789c8201185

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

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

describe Templater::Generator, '.argument as array' do

  before do
    @generator_class = Class.new(Templater::Generator)
    @generator_class.argument(0, :monkey)
    @generator_class.argument(1, :llama, :as => :array)
  end
  
  it "should allow assignment of arrays" do
    instance = @generator_class.new('/tmp', {}, 'a monkey', %w(an array))
    
    instance.monkey.should == 'a monkey'
    instance.llama[0].should == 'an'
    instance.llama[1].should == 'array'
    
    instance.llama = %w(another donkey)
    instance.llama[0].should == 'another'
    instance.llama[1].should == 'donkey'
  end
  
  it "should convert a single argument to an array" do
    instance = @generator_class.new('/tmp', {}, 'a monkey', 'test')
    instance.llama[0].should == 'test'
  end
  
  it "should consume the remaining arguments and convert them to an array" do
    instance = @generator_class.new('/tmp', {}, 'a monkey', 'test', 'silver', 'river')
    instance.llama[0].should == 'test'
    instance.llama[1].should == 'silver'
    instance.llama[2].should == 'river'
  end
  
  it "should raise error if the argument is not an array" do
    instance = @generator_class.new('/tmp')
    lambda { instance.llama = :not_an_array }.should raise_error(Templater::MalformattedArgumentError)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
templater-0.1.4 spec/generator/argument_as_array_spec.rb
templater-0.1.5 spec/generator/argument_as_array_spec.rb
templater-0.1.2 spec/generator/argument_as_array_spec.rb
templater-0.1.3 spec/generator/argument_as_array_spec.rb