Sha256: 495af26d4a72e2062ebde4833c281d1ecd89129c883dd03734f193419a51a19d

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 KB

Contents

require File.join(File.dirname(__FILE__), %w[spec_helper])

describe Loquacious::Configuration::Iterator do

  before(:each) do
    @config = Loquacious.configuration_for 'specs'
    @iterator = Loquacious::Configuration::Iterator.new(@config)
  end

  it 'should find a particular attribute' do
    node = @iterator.find 'first'
    node.name.should == 'first'
    node.key.should == :first
    node.desc.should == 'foo method'
    node.obj.should == 'foo'
    node.config?.should == false

    node = @iterator.find :third
    node.name.should == 'third'
    node.key.should == :third
    node.desc.should == 'the third group'
    node.config?.should == true

    node = @iterator.find('third.answer')
    node.name.should == 'third.answer'
    node.key.should == :answer
    node.desc.should == 'life the universe and everything'
    node.obj.should == 42
    node.config?.should == false
  end

  it 'should return nil for unknown attributes' do
    @iterator.find('last').should be_nil
    @iterator.find('last.first.none').should be_nil
    @iterator.find('third.none').should be_nil
    @iterator.find(:foo).should be_nil
  end

  it 'should iterate over all attributes' do
    ary = Array.new
    @iterator.each {|n| ary << n.name}

    ary.should == %w{first second third third.answer third.question}
  end

  it 'should iterate over nested attributes if given' do
    ary = Array.new
    @iterator.each('third') {|n| ary << n.name}
    ary.should == %w{third third.answer third.question}

    ary.clear
    @iterator.each('first') {|n| ary << n.name}
    ary.should == %w{first}

    ary.clear
    @iterator.each('not_here') {|n| ary << n.name}
    ary.should be_empty
  end
end

# EOF

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
TwP-loquacious-1.0.0 spec/iterator_spec.rb
TwP-loquacious-1.1.0 spec/iterator_spec.rb
TwP-loquacious-1.1.1 spec/iterator_spec.rb
TwP-loquacious-1.3.0 spec/iterator_spec.rb
loquacious-1.6.1 spec/iterator_spec.rb
loquacious-1.6.0 spec/iterator_spec.rb
loquacious-1.5.2 spec/iterator_spec.rb
loquacious-1.5.1 spec/iterator_spec.rb
loquacious-1.5.0 spec/iterator_spec.rb
loquacious-1.4.2 spec/iterator_spec.rb
loquacious-1.4.1 spec/iterator_spec.rb
loquacious-1.4.0 spec/iterator_spec.rb
loquacious-1.3.1 spec/iterator_spec.rb
loquacious-1.2.0 spec/iterator_spec.rb
loquacious-1.1.0 spec/iterator_spec.rb
loquacious-1.0.0 spec/iterator_spec.rb
loquacious-1.1.1 spec/iterator_spec.rb
loquacious-1.3.0 spec/iterator_spec.rb