require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'builder' describe "Response" do describe "parse" do it "should convert an xml response body into a hash" do @xml = < 1 Success 1 12345678 0 0 EOXML @response_hash = { "SmsReturn" => { "StatusCode"=>"1", "StatusText"=>"Success", "Completed"=>"1", "TextID"=>"12345678", "Demo"=>"0", "ScheduledTime"=>nil, "Responded"=>"0", "xmlns"=>"http://ws.cdyne.com/SmsWS/", } } SmsNotify::Response.parse(@xml).should == @response_hash end it "should convert multiple responses into an array of hashes" do @xml = < e3h8a2b e3dc20 5 Hello h2a0cd8 c58a9d0 4 Hello again EOF @response_array = { "ArrayOfSmsResponse" => { "xmlns"=>"http://ws.cdyne.com/SmsWS/", "SmsResponse" => [ { "ResponseID" => 'e3h8a2b', "TextID" => 'e3dc20', "StatusCode" => '5', "ReceivedDate" => nil, "Message" => 'Hello' }, { "ResponseID" => 'h2a0cd8', "TextID" => 'c58a9d0', "StatusCode" => '4', "ReceivedDate" => nil, "Message" => 'Hello again' } ] } } SmsNotify::Response.parse(@xml).should == @response_array end end end