Hi. I am working on a webservice producing xml content, In my rails functional test I would like to assert that this generated xml (@reponse.body) conforms to a specific XSD. What is the best approach to do this? Jarl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 19 Nov 2008, at 13:07, Jarl Friis wrote:> > Hi. > > I am working on a webservice producing xml content, In my rails > functional test I would like to assert that this generated xml > (@reponse.body) conforms to a specific XSD. > > What is the best approach to do this? >Dunno about best approach but I recently did something along those lines (in this particular case I was generating xml to send to a webservice rather than your way round, but I don''t think that''s relevant) in the end I just popened xmllint and piped my xml in. The ruby libxml bindings might allow you do stuff like that, I didn''t look very closely at that. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the reply. Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:> On 19 Nov 2008, at 13:07, Jarl Friis wrote: > >> >> Hi. >> >> I am working on a webservice producing xml content, In my rails >> functional test I would like to assert that this generated xml >> (@reponse.body) conforms to a specific XSD. >> >> What is the best approach to do this? >> > Dunno about best approach but I recently did something along those > lines (in this particular case I was generating xml to send to a > webservice rather than your way round, but I don''t think that''s > relevant) > in the end I just popened xmllint and piped my xml in.Cool, but xmllint only validates against a DTD, right? I am interested in (a more strict) validation against a XSD. Jarl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2008, at 10:56, Jarl Friis wrote:> > Thanks for the reply. > > Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > >> On 19 Nov 2008, at 13:07, Jarl Friis wrote: >> >>> >>> Hi. >>> >>> I am working on a webservice producing xml content, In my rails >>> functional test I would like to assert that this generated xml >>> (@reponse.body) conforms to a specific XSD. >>> >>> What is the best approach to do this? >>> >> Dunno about best approach but I recently did something along those >> lines (in this particular case I was generating xml to send to a >> webservice rather than your way round, but I don''t think that''s >> relevant) >> in the end I just popened xmllint and piped my xml in. > > Cool, but xmllint only validates against a DTD, right? I am interested > in (a more strict) validation against a XSD.Does both as far as I know ( I only had an xsd anyway) Fred> > > Jarl > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:> Does both as far as I know ( I only had an xsd anyway)Thanks. the xmllint help says --schema schema : do validation against the WXS schema I have never seen "WXS" as an abreviation for XML Schema Definition files. I now made a small rails test helper like this: require ''open3'' class ActionController::TestCase def assert_xsd_validity(xsd, xml = @response.body ) assert test(?e, xsd), "#{xsd} does not exist" xml_temp_file = Tempfile.new("xsd_helper_tempfile") xml_temp_file.write xml xml_temp_file.close command_line = "/usr/bin/env xmllint -noout --schema #{xsd} #{xml_temp_file.path}" err = "" Open3.popen3(command_line){|stdin, stdout, stderr| stdin.close out = stdout.read err = stderr.read } assert_equal "#{xml_temp_file.path} validates\n", err end end Jarl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 21 Nov 2008, at 11:13, Jarl Friis wrote:> > Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > >> Does both as far as I know ( I only had an xsd anyway) > > Thanks. the xmllint help says > --schema schema : do validation against the WXS schema > > I have never seen "WXS" as an abreviation for XML Schema Definition > files. >stands for W3C XML schema apparently :-) Fred> I now made a small rails test helper like this: > > require ''open3'' > class ActionController::TestCase > def assert_xsd_validity(xsd, xml = @response.body ) > assert test(?e, xsd), "#{xsd} does not exist" > xml_temp_file = Tempfile.new("xsd_helper_tempfile") > xml_temp_file.write xml > xml_temp_file.close > command_line = "/usr/bin/env xmllint -noout --schema #{xsd} > #{xml_temp_file.path}" > err = "" > Open3.popen3(command_line){|stdin, stdout, stderr| > stdin.close > out = stdout.read > err = stderr.read > } > assert_equal "#{xml_temp_file.path} validates\n", err > end > end > > > Jarl > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---