Ruby On Rails: Testing
Why don't you subscribe to my blog while you're here? I'm a freelance web developer and I blog about Ruby, Rails, and business online.
Go ahead and subscribe to my RSS feed. Thanks for visiting!
Started ............... Finished in 1.733 seconds. 15 tests, 136 assertions, 0 failures, 0 errors
“Ruby On Rails”:http://rubyonrails.com is a fantastic piece of work. The great thing about RoR is that it has made a heap of decisions for you, so all you have to do is fill in your business logic. What I have only recently realised since getting a bit more serious about my development is that RoR has testing baked right in to the system. RoR provides scripts that you run to create a basic framework for each logical unit of code (E.g. People, Cars, Employees). Not only does RoR create the framework for your business logic but it also creates complementary tests, and even mock data! This saves a heap of time. Beyond this, the mock data (fixtures) can be dynamic so you can store encrypted passwords as code so you always know what the mock password is. RoR’s integration of tests goes further than what I have described. I wonder if I can describe the functional spec of my project through tests and docs then palm off the grunt work to someone else? Hrmm….
Something I suspect many RoR users don’t realise is that they can run:
rake --tasks<p>to see a bunch of powerful RoR "bonus" features such as:</p> <ul> <li>Cloning the test schema automatically from the development schema.</li> <li>Dumping the schema to either a RoR based schema language for DB independence or alternatively SQL if you don"t mind incompatible SQL hell.</li> <li>Running functional or other tests. Even running only recently changed stuff.</li> <li>Auto doc generation.</li> <li>Database upgrade/downgrade. You write patches using RoR"s helpers so no more cryptic SQL upgrade scripts. You end up with something like:</li> <pre> class AddUserEmail < ActiveRecord::Migration #Auto run when upgrading db. def self.up add_column :users, :email, :string end #Auto run when downgrading db. def self.down remove_column :users, :email end end
Now, even the least database fluent developer can understand that.
Many Java nerds will automatically point to Ant when reading this stuff. But I get all of the above stuff for free! There’s no need to stuff around with XML configuration or customisation. I’m not hugely familiar with the Java world but I’m sure there are tools to do all this stuff. Even so, wouldn’t you rather these solutions just “be there” and ready to go? Also, I’m not tied to some flashy bloated IDE which is good because sometimes I code on an old P3 server through vi, screen, and a remote SSH session - the way God intended us to code.
Anyway, it’s bloody brilliant. Get your head out of the sand and check it out.


December 27th, 2005 at 10:22 am