How to use ZenTest?


#1

OK, supposedly it has Rdoc documentation but I couldn’t find it (not
helped
by the fact that I’ve never used offline rdocs so I don’t really know
where
to look).

So, does anybody know how to use ZenTest effectively with Rails? I read
all
I could find on the web but nothing really illuminated for me. I’m
trying to
get into Test Driven Development (I have already written a lot of code
for
my project but not a single line of test code - eek - so I’m working
backwards until I get to the point where TDD can pull ahead).

How do I generate the test files for all of my controllers and models
with
ZenTest? Not individually, me hopes.

TIA,
Dave


#2

On Apr 16, 2006, at 4:56 PM, Dave Myron wrote:

OK, supposedly it has Rdoc documentation but I couldn’t find it
(not helped by the fact that I’ve never used offline rdocs so I
don’t really know where to look).

gem_server

So, does anybody know how to use ZenTest effectively with Rails? I
read all I could find on the web but nothing really illuminated for
me. I’m trying to get into Test Driven Development (I have already
written a lot of code for my project but not a single line of test
code - eek - so I’m working backwards until I get to the point
where TDD can pull ahead).

Its just ruby. You don’t need to do anything special.

See also autotest and Test::Rails now in ZenTest 3.2.0.

How do I generate the test files for all of my controllers and
models with ZenTest? Not individually, me hopes.

I think I’ve got nearly full coverage, so this isn’t a good example:

$ rake stats
(in /Users/drbrain/Work/svn/robotcoop/trackmap/trunk)
±---------------------±------±------±--------±--------±----
±------+
| Name | Lines | LOC | Classes | Methods | M/C |
LOC/M |
±---------------------±------±------±--------±--------±----
±------+
| Libraries | 357 | 243 | 9 | 21 | 2
| 9 |
| Models | 175 | 109 | 5 | 15 | 3
| 5 |
| Unit tests | 842 | 660 | 10 | 65 | 6
| 8 |
| Controllers | 564 | 453 | 6 | 39 | 6
| 9 |
| Controller tests | 1600 | 1271 | 7 | 159 | 22
| 5 |
| View tests | 481 | 328 | 5 | 25 | 5 |
11 |
| Helpers | 11 | 8 | 0 | 1 | 0
| 6 |
±---------------------±------±------±--------±--------±----
±------+
| Total | 4030 | 3072 | 42 | 325 | 7
| 7 |
±---------------------±------±------±--------±--------±----
±------+
Code LOC: 813 Test LOC: 2259 Code to Test Ratio: 1:2.8

My tests are very well factored, so fully expanded I probably have a
code to test ratio of 1:4. Test::Rails helps remove many of the
redundancies as well.

I also test ApplicationController in DummyController so that filters
can be properly tested.

$ zentest -r config/environment.rb app/controllers/application.rb app/
controllers/point_controller.rb test/controllers/
point_controller_test.rb

Code Generated by ZenTest v. 3.2.0

classname: asrt / meth = ratio%

PointController: 169 / 7 = 2414.29%

ApplicationController: 0 / 8 = 0.00%

require ‘test/unit’ unless defined? $ZENTEST and $ZENTEST

class ApplicationControllerTest < Test::Unit::TestCase
def test_log_error
raise NotImplementedError, ‘Need to write test_log_error’
end

def test_rescue_action_in_public
raise NotImplementedError, ‘Need to write
test_rescue_action_in_public’
end

def test_url_for
raise NotImplementedError, ‘Need to write test_url_for’
end

def test_user
raise NotImplementedError, ‘Need to write test_user’
end

def test_user_loggedin
raise NotImplementedError, ‘Need to write test_user_loggedin’
end

def test_user_owns
raise NotImplementedError, ‘Need to write test_user_owns’
end
end

Number of errors detected: 7


Eric H. - removed_email_address@domain.invalid - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com