Dear Railers, Please tell me if the following idea has any merit: I want to enhance assert_success from action_pack_assertions.rb so that if some sort of global variable is set, it asserts that @response.body is a parseable XML, or maybe even that it is a valid XHTML. * Why a global variable? Because this kind of assertion is quite slow, and you may not want it to run on every test run. Or you may not even care about this requirement at all. * Why assert_success? Because you call it for every controller test that is supposed to respond with an HTML, not a redirect instruction. Needless, to say, some of the controllers do not produce HTML at all, therefore it should be possible to override this validation locally, such as assert_success :skip_xhtml_validation -- Best regards, Alexey Verkhovsky Ruby Forum: http://ruby-forum.org (moderator) RForum: http://rforum.andreas-s.net (co-author) Instiki: http://instiki.org (maintainer)
Alexey Verkhovsky wrote:> Dear Railers, > > Please tell me if the following idea has any merit: > > I want to enhance assert_success from action_pack_assertions.rb so that > if some sort of global variable is set, it asserts that @response.body > is a parseable XML, or maybe even that it is a valid XHTML. > > * Why a global variable? Because this kind of assertion is quite slow, > and you may not want it to run on every test run. Or you may not even > care about this requirement at all. > > * Why assert_success? Because you call it for every controller test that > is supposed to respond with an HTML, not a redirect instruction. > > Needless, to say, some of the controllers do not produce HTML at all, > therefore it should be possible to override this validation locally, > such as > > assert_success :skip_xhtml_validation >Not that I think this is a bad idea, but why not just have an assert_valid_xml and assert_valid_xhtml? Also, what are you considering using for XHTML validation? I''ve always been a little interested in something that could check XHTML validity from my FTs because validating pages that need authentication can be a pain to do by hand. Thoughts on this? -Scott _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Scott Barron wrote:> Not that I think this is a bad idea, but why not just have an > assert_valid_xml and assert_valid_xhtml?because (a) I want this to be disabled by default and enabled by exception (Reason: I run unit tests ~100 times a day, 10 seconds difference counts) (b) In 99.99% of cases, wherever I have assert_success, I discover that I want to have "assert_valid_xml unless $skip_xml_validation" written right next to it. That''s asking for some refactoring. (c) .001% of cases is when the controller is generating Tex.> Also, what are you considering using for XHTML validation?Don''t know, but I''d love to have _something_ smarter than REXML::Document.new(@response.body) - that''s for sure. -- Best regards, Alexey Verkhovsky Ruby Forum: http://ruby-forum.org (moderator) RForum: http://rforum.andreas-s.net (co-author) Instiki: http://instiki.org (maintainer)
On 16 Jan 2005, at 10:52, Alexey Verkhovsky wrote:> Scott Barron wrote: > >> Not that I think this is a bad idea, but why not just have an >> assert_valid_xml and assert_valid_xhtml?You can handle all the below cases in your own code, in test_helper.rb, after loading Rails. I don''t want assert_success to behave magically depending upon a global because if I want a method named assert_success_and_valid if that''s what it really does.> (a) I want this to be disabled by default and enabled by exception > (Reason: I run unit tests ~100 times a day, 10 seconds difference > counts)module Test::Unit::Assertions alias old_assert_valid_xhtml assert_valid_xhtml def assert_valid_xhtml return unless $some_global assert_valid_xhtml end end> (b) In 99.99% of cases, wherever I have assert_success, I discover > that I want to have "assert_valid_xml unless $skip_xml_validation" > written right next to it. That''s asking for some refactoring.module Test::Unit::Assertions alias old_assert_success assert_success def assert_success old_assert_success return unless $some_global assert_valid_xhtml end end> (c) .001% of cases is when the controller is generating Tex.module Test::Unit::Assertions VALIDATORS = {} def assert_valid(content_type, content) # something like VALIDATORS[content_type].validate content end end Test::Unit::Assertions::VALIDATORS[:TeX] = TeXValidator.new # or PassValidator.new -- Eric Hodel - drbrain-48TerJ1FxhPk1uMJSBkQmQ@public.gmane.org - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails