require "spec_helper" describe Gyoku::XMLValue do let(:datetime) { DateTime.new 2012, 03, 22, 16, 22, 33 } let(:datetime_string) { "2012-03-22T16:22:33+00:00" } describe ".create" do context "for DateTime objects" do it "returns an xs:dateTime compliant String" do create(datetime).should == datetime_string end end it "returns the String value and escapes special characters" do create("string").should == "string" create("").should == "<tag>" create("at&t").should == "at&t" create('"quotes"').should == ""quotes"" end it "returns the String value without escaping special characters" do create("", false).should == "" end it "returns an xs:dateTime compliant String for Objects responding to #to_datetime" do singleton = Object.new def singleton.to_datetime DateTime.new 2012, 03, 22, 16, 22, 33 end create(singleton).should == "2012-03-22T16:22:33+00:00" end it "calls Proc objects and converts their return value" do object = lambda { DateTime.new 2012, 03, 22, 16, 22, 33 } create(object).should == "2012-03-22T16:22:33+00:00" end it "calls #to_s unless the Object responds to #to_datetime" do create("value").should == "value" end end def create(object, escape_xml = true) Gyoku::XMLValue.create object, escape_xml end end