Doing some Test::Unit work on my CGI scripts, I wondered if anyone
had done any work combining Test::Unit with CGI?
Specifically, I’m thinking:
Create your Test::Unit test case file. Just as it auto-magically
runs the test runner by simply requiring ‘test/unit’ and defining
a class that inherits from Test::Unit::TestCase, I’m thinking if
you require ‘cgi’ – well, if a class named “CGI” is defined – that
the Test::Unit test runner generates its output as a HTML
document.
Perhaps this is too magical: if your testing a CGI script, it’ll
have a CGI class defined and you may not want the output in HTML.
So, maybe defining a flag would be necessary.
I’m just thinking of an easy way of turning a Test::Unit test
case (or suite) into something that can be published to the web
… or, in my case, run the test cases as a CGI script – each hit
to the CGI runs the test cases and sends the results as HTML
back to the browser.
If anyone has already done this, please speak up! I’d love to
use whatever you’ve got. Otherwise, I’m going to start working
on this now.
– Dossy
···
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
Just as it auto-magically
runs the test runner by simply requiring ‘test/unit’ and defining
a class that inherits from Test::Unit::TestCase, I’m thinking if
you require ‘cgi’ – well, if a class named “CGI” is defined – that
the Test::Unit test runner generates its output as a HTML
document.
It would make your shell run test output uglier, but I think this
should work online. Alternatively, you could have two seperate entry
points to the application, one of which was a cgi:
run_my_tests.rb
cgi_run_my_tests.rb
I don’t think it’s simple to autodetect whether a script is running
within a cgi enviroment. Look at the code for the QueryExtension
module within cgi for the enviroment checking code.
I’m talking more like a test/unit/ui/web/testrunner.rb … which I’ve
got something that “works” for me now already … no unit tests for
it, though. Just a mad copy-and-paste from
test/unit/ui/console/testrunner.rb and test/unit.rb …
On Mon, Jul 15, 2002 at 11:35:25AM +0900, Dossy wrote:
Doing some Test::Unit work on my CGI scripts, I wondered if anyone
had done any work combining Test::Unit with CGI?
I’ve heard of a webunit, but I have not had the chance
to use it yet.
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
This is what the initial version of mine did. Of course,
isn’t
enough – you really want because the expected and actual strings
are guarded with “< … >” and therefore those < and > need to be
HTML escaped as < and > … unless you use …
Now, where my code is at … can pretty much handle everything the
right way, IMHO.
I don’t think it’s simple to autodetect whether a script is running
within a cgi enviroment. Look at the code for the QueryExtension
module within cgi for the enviroment checking code.
I test for ENV[‘GATEWAY_INTERFACE’].nil? which is Good Enough for me.
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
Yes, it’s just mostly copy-and-paste. Yes, I don’t have unit
tests for my changes (yet). Yes, I crammed this together in
probably under an hour – it could use lots of cleaning up, and
some snazzier styling to boot.
I may be inclined to clean things up if there’s interest from
anyone but myself.
On Mon, Jul 15, 2002 at 11:35:25AM +0900, Dossy wrote:
Doing some Test::Unit work on my CGI scripts, I wondered if anyone
had done any work combining Test::Unit with CGI?
I’ve heard of a webunit, but I have not had the chance
to use it yet.
I’m not talking of combining them in that way.
I’m talking more like a test/unit/ui/web/testrunner.rb … which I’ve
got something that “works” for me now already … no unit tests for
it, though. Just a mad copy-and-paste from
test/unit/ui/console/testrunner.rb and test/unit.rb …
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
This is what the initial version of mine did. Of course,
isn’t
enough – you really want because the expected and actual strings
are guarded with “< … >” and therefore those < and > need to be
HTML escaped as < and > … unless you use …
–
Rob | I prefer plaintext email…
“Erm, I don’t want to expose too much of my code, as I’m writing it
fairly plainly at present and I’m sure to be told how all of my
routines can be compressed down into one line with no alphanumeric
characters in them.” [ Ross Clement in comp.lang.perl.misc ]
This is what the initial version of mine did. Of course,
isn’t
enough – you really want because the expected and actual strings
are guarded with “< … >” and therefore those < and > need to be
HTML escaped as < and > … unless you use …