require 'spec_helper' module CSL describe Info do it { should_not be_nil } it { should_not have_children } describe '#nodename' do it 'returns "info"' do subject.nodename.should == 'info' end end describe '#children' do it 'returns a Info::Children instance' do Info.new.children.should be_a(Info::Children) end it 'allows to set the id by writer method' do lambda { Info.new.children.id = 'foo' }.should_not raise_error end it 'allows to set the id by array accessor' do lambda { Info.new.children[:id] = 'foo' }.should_not raise_error end end describe '#category' do it 'returns nil by default' do Info.new.category.should be nil end end describe '#to_xml' do it 'returns an empty info element by default' do subject.to_xml.should == '' end it 'prints the id if present' do Info.new { |i| i.set_child_id 'apa' }.to_xml.should == 'apa' end it 'prints the category if present' do Info.new { |i| i.category = 'author' }.to_xml.should == 'author' end end describe '#pretty_print' do it 'returns an empty info element by default' do subject.pretty_print.should == '' end it 'prints the id indented if present' do Info.new { |i| i.set_child_id 'apa' }.pretty_print.should == "\n apa\n" end end describe '#tags' do it 'returns a list with an empty info element by default' do subject.tags.should == [''] end it 'returns a nested list if id is present' do Info.new { |i| i.set_child_id 'apa' }.tags.should == ['', ['apa'], ''] end end end describe Info::Author do it { should_not be_nil } let(:poe) { Info::Author.new { |a| a.email = 'poe@baltimore.com' a.name = 'E. A. Poe' } } describe '#name' do it 'returns nil by default' do subject.name.should be nil end it 'returns the name if set' do poe.name.to_s.should == 'E. A. Poe' end end describe '#email' do it 'returns the email' do poe.email.to_s.should == 'poe@baltimore.com' end end describe '#to_xml' do it 'returns an empty author by default' do subject.to_xml.should == '' end it 'prints all children' do poe.to_xml.should == 'E. A. Poepoe@baltimore.com' end end end describe Info::Contributor do it { should_not be_nil } let(:bruce) { Info::Contributor.new { |c| c.name = "Bruce D'Arcus" } } describe '#name' do it 'returns the name' do bruce.name.to_s.should == "Bruce D'Arcus" end end describe '#to_xml' do it 'returns an empty contributor by default' do subject.to_xml.should == '' end it 'prints the name tag if present' do bruce.to_xml.should == "Bruce D'Arcus" end end end end