spec/response_spec.rb in relax-0.0.1 vs spec/response_spec.rb in relax-0.0.2

- old
+ new

@@ -13,34 +13,44 @@ <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 TestResponse < Relax::Response class Token < Relax::Response parameter :token_id, :element => :tokenid parameter :status end + class Error < Relax::Response + parameter :code, :type => :integer + parameter :message + end + parameter :status parameter :request_id, :element => :requestid, :type => :integer 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 it 'should allow access to the root' do root = @response.root root.should be_an_instance_of(Hpricot::Elem) - root.name.should eql('restresponse') + root.name.should eql('RESTResponse') end it 'should be checkable by the name of its root' do @response.is?(:RESTResponse).should be_true end @@ -64,11 +74,11 @@ it 'should have a means of checking for the existence of a node' do @response.has?(:Status).should_not be_nil @response.has?(:Errors).should be_nil end - it 'should be able to define children of Request without modifying parent' do + it 'should be able to define children of Response without modifying parent' do Relax::Response.new(XML).respond_to?(:status).should be_false TestResponse.new(XML).respond_to?(:status).should be_true end it 'should automatically pull parameters from the XML' do @@ -76,7 +86,13 @@ response.status.should eql('Success') response.request_id.should eql(44287) response.valid_request.should eql('true') response.tokens.length.should eql(2) response.tokens.first.status.should eql('Active') + response.error.code.should eql(1) + response.error.message.should eql('Failed') + end + + it 'should be relationally equivalent to its children' do + (Relax::Response === TestResponse).should be_true end end