spec/response_spec.rb in relax-0.0.4 vs spec/response_spec.rb in relax-0.0.5

- old
+ new

@@ -1,29 +1,8 @@ require File.dirname(__FILE__) + '/spec_helper' -require 'relax/response' -XML = <<EOF -<?xml version="1.0"?> -<RESTResponse> - <Tokens> - <TokenId>JPMQARDVJK</TokenId> - <Status>Active</Status> - </Tokens> - <Tokens> - <TokenId>RDVJKJPMQA</TokenId> - <Status>Inactive</Status> - </Tokens> - <Status>Success</Status> - <RequestId valid="true">44287</RequestId> - <Error> - <Code>1</Code> - <Message>Failed</Message> - </Error> -</RESTResponse> -EOF - class BaseResponse < Relax::Response parameter :status, :required => true parameter :request_id, :element => :requestid, :type => :integer end @@ -32,19 +11,21 @@ parameter :token_id, :element => :tokenid parameter :status end class Error < Relax::Response + parser :hpricot parameter :code, :type => :integer parameter :message end parameter :valid_request, :element => :requestid, :attribute => :valid parameter :tokens, :collection => Token parameter :error, :type => Error end + describe 'a response' do before(:each) do @response = Relax::Response.new(XML) end @@ -103,7 +84,15 @@ (Relax::Response === TestResponse).should be_true end it 'should raise MissingParameter if required parameters are missing' do proc { TestResponse.new('') }.should raise_error(Relax::MissingParameter) + end + + it 'should use the default parser when undefined' do + TestResponse::Token.new('').parser_name.should ==:default + end + + it 'should use the defined parser when given' do + TestResponse::Error.new('').parser_name.should ==:hpricot end end