Let's start with a hypothetical. You're working on a project, and you need to add some functionality to it that you know someone out there must have already done. So like all good Rubyists, you hit rubygems.org and do a quick search. Sure enough, there's a Gem for that. It'd probably be helpful to know how to use the gem, so let's say the next thing you do is check on the documentation. The README is detailed and helpful, and the gem looks well-designed and promising. What do you do next?
I'll tell you what you should do. You should jump into the gem's spec
or test
directory and see how that's laid out. Are the tests readable and coherent? Can you tell from a glance how a particular object is meant to be used within the context of the gem? Are the examples from the README tested for correctness? Or, are the tests a convoluted mess -- or worse, nonexistent?
Now let's turn the tables. If you write a library and open source it, then kudos to you. Your heart is in the right place. But if you don't test it, then you're not really helping anybody. In fact, if you don't test your code, then all it tells me is that you were either too lazy to do so or you couldn't think of a way to test it properly, and opted not to bother. Either way, I'm not impressed.
Here's the thing. If your code doesn't have tests, or if the tests are so difficult to read that it's impossible to know whether your tests are even doing what they claim they're doing, I'm not going to use your library. Period. If I don't see some decent testing, I'd rather roll my own. At least then I'd know what's in it. Since I test my code, I'll be assured that my code works.
Is this being nit-picky? Maybe I should shut up and be happy that you contributed something in the first place? There're a few problems with this mentality. First of all, your ego is bigger than your ability. Everyone makes mistakes, and if you think you're above them, then that only proves you need to test your code twice as thoroughly as anyone else -- especially if it's written in a dynamic language like Ruby, where a single typo can have catastrophic consequences.
Secondly, untested code is worse than no code at all. Not only does it make it harder to find the good libraries out there, it has a cascading effect on code written by developers who are trying to follow best practices, even if you aren't.
Let me put it this way. I use Ruby on Rails. I don't go and test that fundamental things like database connectivity and params processing are working properly, because I have the assurance that Rails has already been unit tested. I use the framework in good faith, and if I ever suspect that something might be broken, I can run the whole Rails test suite to check as much. I have no need to test every facet of Rails within my own project -- I only need to write tests specific to my project.
Likewise, if a developer uses your library, they are doing so in good faith. They expect your code to be tested. They don't want to -- and probably wouldn't even think to -- unit test every facet of your code. Your library should already have done that. So, if you never bothered to test your code, then even a developer following every possible best practice can't be sure their code is working properly.
I'm not a lazy guy, but I don't always want to reinvent the wheel. Actually, I usually prefer not to. Problem: if I don't have confidence in your code, then I can't use it in my project. Simple as that. Because my projects reflect on me. People see my code and they get an idea of my professionalism. I'm not going to jeopardize my reputation because you were lazy. And as an aside, you should really take your own reputation more seriously. In the Internet age, all a potential (or current) employer has to do is Google you, find your GitHub account, and read your code. Do you really expect anybody to pay you for substandard code?
So, if you're going to go to the effort of writing it, then at least test it. If you can't make yourself do that, then why bother writing it at all?
But, if you insist on pushing out crappy code, I guess that's fine. I can't stop you. Just don't expect anybody to take you seriously.
Well, here we are: my new blog is online! I've dropped the old code base, which was a Rails 2.3.8 app, and completely rewritten the blogging engine as a Rails 3 Engine called Mist.
One of the many awesome things in Rails 3 is the new routing DSL. I was pretty attached to the Rails 2.3 style of doing things, and so I was a bit skeptical, but I have to say: the Rails team has outdone themselves.