Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
require File.join( File.dirname(__FILE__), "..", "spec_helper" ) describe DataMapper::Serialize do class Cow include DataMapper::Resource property :id, Integer, :serial => true property :name, String property :breed, String end before(:all) do properties = Cow.properties(:default) properties_with_indexes = Hash[*properties.zip((0...properties.length).to_a).flatten] @collection = DataMapper::Collection.new(DataMapper::repository(:default), Cow, properties_with_indexes) @collection.load([1, 'Betsy', 'Jersey']) @collection.load([10, 'Berta', 'Guernsey']) end describe "#to_xml" do it "should serialize a resource to XML" do berta = Cow.new berta.id = 89 berta.name = 'Berta' berta.breed = 'Guernsey' berta.to_xml.should == <<-EOS <?xml version="1.0" encoding="UTF-8"?> <cow> <id>89</id> <name>Berta</name> <breed>Guernsey</breed> </cow> EOS end it "should serialize a collection to XML" do @collection.to_xml.gsub(/[[:space:]]+\n/, "\n").should == <<-EOS <?xml version="1.0" encoding="UTF-8"?> <cows> <cow> <id>1</id> <name>Betsy</name> <breed>Jersey</breed> </cow> <cow> <id>10</id> <name>Berta</name> <breed>Guernsey</breed> </cow> </cows> EOS end end end
This paste will be private.
From the Design Piracy series on my blog: