If you're lazy and you know it write your specs!
Sun Apr 04 04:43:28 -0700 2010
You need to sing that title along to this tune but it struck me as a great idea for a post.
As you probably all know, I code the Mail library for Ruby. When I announced my intentions to the TMail mailing list last year, I had a bunch of people say “Don’t bother, it’s too big a job” or “just wrap the libmime library”. But I decided to try it out, I mean, how hard could it be?
Hard.
No really. It’s a real pain covering all the edge cases. Email is probably one of the most abused specifications out there, actually. No. I think it is THE most abused specification out there. Even the worst HTML pages are better put together than your average spam email. And there are millions of spam emails.
But when I started on Mail, I made a conscious decision to spec first the entire library, and as it stands today, there are over 1300 specs in Mail.
The first spec I wrote was actually this one (which is still in the library):
describe "mail" do
it "should be able to be instantiated" do
doing { Mail }.should_not raise_error
end
end
One of the more narly ones is:
it "should handle |Pete(A wonderful ) chap) <pete(his account)@silly.test(his host)>|" do
address = Mail::Address.new('Pete(A wonderful \) chap) <pete(his account)@silly.test(his host)>')
address.should break_down_to({
:name => 'Pete',
:display_name => 'Pete',
:address => 'pete(his account)@silly.test',
:comments => ['A wonderful \\) chap', 'his account', 'his host'],
:domain => 'silly.test',
:local => 'pete(his account)',
:format => 'Pete <pete(his account)@silly.test> (A wonderful \\) chap his account his host)',
:raw => 'Pete(A wonderful \\) chap) <pete(his account)@silly.test(his host)>'})
end
What has this got to do with being lazy? Easy, if you have a full spec (or test) suite and you change something, you can track the impact there is on the entire library.
So when I get an email that breaks mail, I load it into the spec suite, and run it, get a failure, then go ahead and change code with aplomb, each time running the specs.
There is a huge sense of security knowing you have thorough spec coverage.
I have another application, consisting of over 50,000 lines of code (combined specs, features and code itself) which I wrote for a client. I had to go back to it 7 months after I wrote it (having basically not touched it for this time) and add a new feature.
The first thing I did was make sure the spec suite was running. It was, mostly, another coder had made some changes and not updated the specs and features, so there were a few failures. So I got to work and got it green.
Then making the change was trivial, I didn’t have to worry too much about unintended consequences as I know the spec and feature set was very thorough. The client is also rewarded with a highly maintainable application that is mostly error free and has been running happily along.
The point is, that if you are not thorough writing test / specs / features with your Rails app. Then you are not doing your job in a professional manner, simple as that.
But the good point is, if you like being lazy (and not having to spend HOURS trying to debug the latest problem with your code), write your specs and features as you go. You will save yourself (and your client / boss / life) countless hours of frustration.
blogLater
Mikel




Tue Nov 08 19:43:14 -0800 2011
Your post has been linked at the Drink Rails blog roll for the day.
Fri Jul 29 00:59:02 -0700 2011
Nice words. This not only apply on Rails developers. Even to anyone who is writing code. I have been a Systems Analyst for 2 years at the same time a member of Millionaire Mind Intensive, and writing specs is very important for us. This way, it can save time and effort for both the application developer and the test engineer as well.
Sun Feb 05 20:29:36 -0800 2012
Such an amazing blog you have posted dear i like it and also suggesting it to What is the illuminati my friends for visiting your blog The Illuminati Faith because it has really admirable and informative data which provide us through your blog so i would like to thank you for sharing it with us and also appreciate you on this so keep it up.
Sun Feb 19 13:17:25 -0800 2012
People can use writing skill to get money. They can sell the work to the publisher. People who like writing usually have great passion on it. index futures
Tue Feb 28 22:26:08 -0800 2012
Many people use composing skill to have funds. However, very few individuals utilize it as the very initial work. This generally will become the pastime. forex iphone
Sun Mar 11 04:36:43 -0700 2012
We should be proud of what we are strong at and cover our weaknesses. That is how some kind of people can get out strong and achieve what they want.
Tue Mar 13 07:30:20 -0700 2012
and if I can not write my specs then who will do it? I should do it myself
Wed Mar 14 07:21:41 -0700 2012
I know what to write, but is a boring thing to do. I prefer to delay this thing.
Thu Apr 12 00:05:56 -0700 2012
I will do it myself. It is easy and I will know that it will be original.