Making Rcov measure your whole Rails app, even if tests miss entire source files

I’ve seen a few Rake tasks for Rcov that work OK, but which fail in an interesting way (if you care about coverage): they give your coverage metrics an unexpected boost if you have 0% coverage in one or more source files.

Huh? Exactly. If you have 500 source files, and your test suite only requires one of them, then you get a free ride on those 499 files that have 0% coverage. Theoretically you could get 100% coverage in your report even though 499 source files are not touched at all. D’oh!
Read the rest of this entry »

Rails snippet: require app files only once

Ruby’s Kernel.require method will re-require the same source file if you pass it differing arguments that point to the same file. It doesn’t use File.expand_path to make sure it hasn’t already loaded the same file before. This can cause problems if you’re using constants or doing one-time initialization in a source file that’s getting loaded multiple times for one reason; you’ll need to add a wrapper that prevents re-entry.

If this annoys you as much as it does me (why should my application code include workarounds for what I regard to be a Ruby bug?), add this snippet to your config/environment.rb (pre Rails 2.0) or config/preinitializer.rb (Rails 2.0 or later).
Read the rest of this entry »

Recommended mount options for ext3

The details of the various mount options for the ext3 filesystem are fairly well documented, but as with many things in the Unix world, knowledge is far easier to come by than wisdom. That’s a pithy way of saying that I had to do some digging to find recommendations, as opposed to explanations. So here are my recommendations for ext3 users (which encompasses the majority of the Linux-using world, as far as I can tell).
Read the rest of this entry »

Save power and heat: spin down backup drives when idle

Here’s a tip for those of you who, like me, back up your data to hard disks instead of tapes. Backing up to the same hard disk doesn’t protect you much (if the disk failed, you’d lose the data and the backup at once), so presumably you’re backing up to a separate physical drive. That means that the backup drive need not spin 24/7. Instead, it only needs to spin at backup time.
Read the rest of this entry »

Retroactively Minimizing Installed Packages on CentOS 5.1

In my CentOS 5.1 Minimal VPS Install Guide I describe how to install a very lean set of OS packages when starting from scratch. But what if the VPS is preinstalled for you by a hosting provider? There will be things preinstalled that you don’t need, which will slow down backups and updates, and waste the relatively tiny amount of disk space that VPS plans offer. So here are some instructions to help you identify and remove packages that you don’t need, when they’ve already been installed.
Read the rest of this entry »