Ruby on Rails Testing: Some Basic Tips

At some point after you’ve started building your first Rails application, you are going to ask yourself, does this application work the way it’s intended to? If you aren’t asking this question, it means you aren’t a good enough application developer. No application can be built to be perfect, and the only way to get there is to make sure your tests are good enough.

The Rails framework has a lot of tools to help you build a comprehensive, and easy to undestand, set of tests. Surprisingly though, the testing framework in Rails is not nearly as intuitive as the basic development framework, so here are a few tips to get you started.

The Normal Distribution Is Your Friend

[Editor’s note: I never got around to completing this post, but this post I just read about how the sound of popcorn being popped is the sound of the normal distribution seemed like a worthy addition to this post.]

Many everyday problems that involve statistics require making many observations about something quantifiable and being able to figure out the most probable value of that observation. For example, maybe you’re trying to figure out what mileage your car’s giving you, so every time you fill the tank up, you record how many miles you go before you empty it out. You might ask, what is the average distance my car will go on a full tank?

One way to solve this problem is to take an average of all your observations. The simple average is not a very good statistical measure, mainly because it’s influenced by “outliers.”  If one of the observations you took of how many miles you went on a full tank of gas involved a very long highway road trip, then the average measure will make it look like you get really awesome mileage. That’s why car companies have to report a highway and a city mileage – the average highway mileage is bound to be higher than the average city-only mileage, and taking an average that combines the two would be misleading. Continue reading “The Normal Distribution Is Your Friend”

Learning Programming: Data and Variables

Programming involves two important concepts – code and data. Code is where all the action is, and data is what the action is all about.

Code will “do things,” like print messages to a screen or in a browser, perform calculations, examine information and make decisions based on various rules and so on. Data is how we represent information to the computer – note that data is fed as inputs to a function and can be created via the outputs created by functions.

In a spreadsheet, we have seen that code is embodied in formulae, or functions. Data is embodied in the values you see in each cell. This leads us to a discussion of the next important concept: how does the code make references to the data that it consumes and creates? This is through variables.

Continue reading “Learning Programming: Data and Variables”

Building Your Own Gem: Adventures in Ruby Programming

I just built my second gem – I thought I’d have written about the first, but somehow it escaped my attention. The first one is already on RubyGems, and generates a seed for you from the Weather Underground API by pulling together a string from some of the weather data on the feed.

When I started writing the second one, I realized that I didn’t remember the very first command I had run to create the gem’s template files – the gemspec, the lib/ and test/ folder, and so on. So here’s a quick round-up of some good tutorials on gem-cutters. I used bundle btw, and here’s a shameless plug: I’ve uploaded a slightly modified set of template files generated from bundle gem, with this one including the requisite files to write tests using minitest. Continue reading “Building Your Own Gem: Adventures in Ruby Programming”

More LAMP adventures: Setting up SSL on Apache/Ubuntu

Ready to run an SSL server on your Ubuntu install? Here how you do it, in a few easy steps.

We will do this for an Apache2 server configuration on Ubuntu – if you’re using a different flavor of Linux (Debian, Fedora, etc.), many of these instructions are similar. I’ll try to keep track of where the major differences are.

Remember that SSL isn’t the default mode for an Apache server installation. So you have to enable the corresponding module, and also set up an SSL certificate for the server to present.

Continue reading “More LAMP adventures: Setting up SSL on Apache/Ubuntu”