Tags
webcam vindaloo version vegan unix unicef trojan todo thinkpad textmate testing tagging syntax svn subversion sphinx spaces solaris sitemap sinatra sheet security search schema_info SchemaInfo ruby rinari relationships refresh rdiff-backup ramaze railsconf08 railsconf07 rails protools production power placeboeffect pink floyd PIC perl overheat outbreak osx os x NYHS NYC netbeans nanophotonics mysql music MPEG-4 model migration microvolunteer macbook mac log linux less leopard keynote JAX javascript java imunizator highlighting Handbrake haml hacks google geocoding genghistron gem gaming gabrielle's funny functional fun friends food fixes fixed firefox FF3 ferret fantasy' emacs DV donate datarecovery database D&D converter conference computing cheat capistrano business bribesThe Hacker said on Mon Apr 07 17:16:36 +0000 2008 | permalink
Tagged: ruby rails functional testing
A Window Into Functional Tests
So like any ruby blooded human, I create functional tests for my rails applications. However, things don’t always go as planned; a redirect instead of a success, but where to?, the assigns is right, but the flash was wrong, etc.
Sometimes you just need a way to peek at what you get back. If you enjoy gouging your eyes out you can do a puts @response or @response.body
A slightly better alternative is to spit the body to a file and preview it in firefox.
tmpfile = File.new(tmpname = 'tmp/test_page.html', "w")
tmpfile.puts @response.body
tmpfile.close
`firefox #{tmpname}`
Put this after any get, post, etc, and you will get a decent html output of your view (sans stylesheets and valid links) Although nothing is stopping you from outputting to public, running script/server, and viewing it from there.
- If your dealing with redirects, don’t forget about follow_redirect!
- If your crossing controllers, use integration tests =)
It’s not the be all end all of solutions, but it helps for a quick glimpse while fixing tests. Hope it helps!