spec/csl/info_spec.rb in csl-1.0.0.pre2 vs spec/csl/info_spec.rb in csl-1.0.0.pre3
- old
+ new
@@ -5,10 +5,12 @@
describe Info do
it { should_not be_nil }
it { should_not have_children }
+ let(:info) { Info.new }
+
describe '#nodename' do
it 'returns "info"' do
subject.nodename.should == 'info'
end
end
@@ -16,24 +18,49 @@
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
+ Info.new.category.should be_nil
end
end
+
+ describe 'link accessors' do
+ it { should_not have_self_link }
+ it { should_not have_documentation_link }
+ it { should_not have_template_link }
+
+ it 'self_link is nil by default' do
+ Info.new.self_link.should be_nil
+ end
+
+ it 'returns nil if no suitable link is set' do
+ Info.new {|i| i.link = {:href => 'foo', :rel => 'documentation'} }.self_link.should be_nil
+ end
+
+ it 'returns the href value of the link if it is set' do
+ Info.new {|i| i.link = {:href => 'foo', :rel => 'self'} }.self_link.should == 'foo'
+ end
+
+ it 'setter changes the value of existing link' do
+ info = Info.new {|i| i.link = {:href => 'foo', :rel => 'self'} }
+ expect { info.self_link = 'bar' }.to change { info.self_link }.from('foo').to('bar')
+ end
+
+ it 'setter creates new link node if link did not exist' do
+ expect { info.self_link = 'bar' }.to change { info.has_self_link? }
+ info.links[0].should be_a(Info::Link)
+ end
+
+ end
describe '#to_xml' do
it 'returns an empty info element by default' do
subject.to_xml.should == '<info/>'
end
@@ -41,10 +68,10 @@
it 'prints the id if present' do
Info.new { |i| i.set_child_id 'apa' }.to_xml.should == '<info><id>apa</id></info>'
end
it 'prints the category if present' do
- Info.new { |i| i.category = 'author' }.to_xml.should == '<info><category>author</category></info>'
+ Info.new { |i| i.category = {:'citation-format' => 'author'} }.to_xml.should == '<info><category citation-format="author"/></info>'
end
end
describe '#pretty_print' do
it 'returns an empty info element by default' do
\ No newline at end of file