Really Testing with Rails (and Agiledox)

Agiledox rake task -- add this to your Rakefile document in your Rails root.

CODE:
  1. desc "Generate agiledox-like documentation for tests"
  2. task :agiledox do
  3.   tests = FileList['test/**/*_test.rb']
  4.   tests.each do |file|
  5.     m = %r".*/([^/].*)_test.rb".match(file)
  6.     puts m[1]+" should:\n"
  7.     test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/}
  8.     test_definitions.each do |definition|
  9.       m = %r"test_(should_)?(.*)".match(definition)
  10.       puts " - "+m[2].gsub(/_/," ")
  11.     end
  12.   puts "\n"
  13.  end
  14. end

Then run:
> rake agiledox

Assuming you've followed a well-behaved naming structure in your test cases (outlined here), you'll receive output like this:

security_controller should:
- redirect to page stored in session on successful login
- store user object in session on successful login
- redirect to page stored in session after signup
- store user object in session after signup

All this via Ben Griffiths, a former ThoughtWorker. Everytime I come across another ThoughtWorker's blog, usually just randomly, I'm always more and more impressed with their whole organization.

[+] Code hilighting above via the iG:Syntax Hiliter Plugin for WordPress.

You can Bookmark this entry on del.icio.usbookmark this, digg this entrydigg this or check the See this page in technoraticosmos


Shanti A. Braford blogs here.

If you really want to know, just read this.



  

Powered by FeedBlitz