require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require example('library')
describe Library do
before :all do
book = Novel.new
book.isbn = "0201710897"
book.title = "The PickAxe"
book.description = "Best Ruby book out there!"
book.author = "David Thomas, Andrew Hunt, Dave Thomas"
book.publisher = Publisher.new('Addison Wesley Longman, Inc.')
@lib = Library.new
@lib.name = "Favorite Books"
@lib.novels = [book]
end
describe "#to_xml" do
it "should contain the expected information" do
@lib.to_xml.should == ROXML::XML::Parser.parse(%{The PickAxeDavid Thomas, Andrew Hunt, Dave ThomasAddison Wesley Longman, Inc.}).root
end
context "when written to a file" do
before :all do
@path = "spec/examples/library.xml"
@doc = ROXML::XML::Document.new
@doc.root = @lib.to_xml
@doc.save(@path)
end
after :all do
FileUtils.rm @path
end
it "should be contain the expected xml" do
ROXML::XML::Parser.parse(File.read(@path)).to_s.should == ROXML::XML::Parser.parse(%{The PickAxeDavid Thomas, Andrew Hunt, Dave ThomasAddison Wesley Longman, Inc.}).to_s
end
it "should be re-parsable via .from_xml" do
File.open("spec/examples/library.xml") do |file|
Library.from_xml(file).should == @lib
end
end
end
end
end