Archive for May, 2007

Smash Stuff

Sunny Days

Very few people can understand why six guys would give up lounging around in the sun on a Friday afternoon, to spend it sealed inside a garage wrapped in black plastic in complete darkness while we throw projectiles at water filled containers. The people who do understand, are those that have experienced the event.

It was nigh time for another Smashening session. This one had more than the usual amount of starting problems, being that we were lacking some of the most fundamental pieces of the timing rig, but after we enjoyed some fine dinner, and some patch jobs we were ready to start breaking things.

There is no disagreement that this photo is the king of the crop. Although it did require some post-production love in order to remove the projectile and an unsightly hot spot, it did come out the best looking photograph of the set. In my opinion the second best of show was this photo, but I think some of the other lads may disagree.

Comments (1)

An Example of RSpec

Intense

I've taken a real shining to Behaviour Driven Development since working on my last project. BDD is the next evolution of Test Driven Development, and basically you think about all the behaviours of your system first. Then you write them down (key step here!), and then make your application meet these define behaviours. On a couple of my side projects, I've started using RSpec to implement some BDD.

When I first started out, I noticed a great void of coherent examples on how to use RSpec. Partially because RSpec was changing which broke old tutorials and tests, and partially because the people writing stuff down were so far out on the edge, that what they had didn't help me out in the slightest. I'm throwing this out there, so that you can see how easy it can be to add a specification test to your rails application.

You'll need to have rails, and rspec installed for this to work. Roll out a vanilla rails application and install the rspec plugins:


# rails myapp
# cd myapp
# ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/REL_1_0_0/rspec
# ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/REL_1_0_0/rspec_on_rails

Add the -x flag to the install command if your code is already in subversion so that svn:extern is used and you can pick up RSpec updates. Now, we need to bootstrap rspec, and create the user object we are going to be writing specifications for:


# ruby script/generate rspec
# ruby script/generate rspec_model user

Now that all the monkey work is done, we can get down to business, I quickly modified the db/migrate/001_create_user.rb to read:


class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.column "identity", :string
    end
  end

  def self.down
    drop_table :users
  end
end

Boring, eh? Well I'm trying to keep it that way. These examples can really get out of hand, if you aren't careful. What we have is the simplest user model ever, all it's got is an identity column. Within my application, I would like it to be impossible for a user to exist without an identity. Simple enough, so I modify /spec/models/user_spec.rb to be:


require File.dirname(__FILE__) + '/../spec_helper'

describe User, " in General" do
  before(:each) do
    @users = User.new
    #Identity is a required field
    @users.identity = "http://whatever.com"
  end

  it "should be valid" do
     @users.should be_valid
  end

  it "should be invalid without an identity" do
    @users.identity = nil
    @users.should_not be_valid
  end
end

The first specification is so trivial it appears silly. It is a valid (and it is already in the generated *_spec.rb file) specification, and will blow up if people change what it means for your model to be valid without updating the specification. The rest almost reads itself. You can see we are describing a User, " in General" and that we have two specification, it should be valid, and it should be invalid without and identity. Pretty simple, eh? Well, let's keep it that way. You can now run the specification test:


# rake spec

Uh, oh! FAILURES! Written in red (on colour TTY) is 'User in General should be invalid without an identity' FAILED. Well, of course, we haven't written any code to invalidate a user without a identity; up to this point, we've only been writing specifications. To make our application meet the meager specifications I changed the app/models/user.rb to be:


class User < ActiveRecord::Base
  validates_presence_of :identity, :message => "Identity is required"
end

Now if I run the rake spec again, I can see that my application is up to specification. That's it. Done, Kaput, and still useless. But, at least we have a starting point. The next steps would be to write down more specifications, and then make the application pass those specifications tests. Repeat, until you have an application that meets all your specifications. Some other nifty things that rspec can bring to the table are rake spec:doc which writes out some bullet point specification (Great to give to the pointy haired manager when he comes askin' what specification to which you were building the application. rake spec:rcov will give you a coverage report of your specification tests (in case you cheated and went ahead writing code without specifying it's behaviour). Already my application has a pile of specifications written for it, and it's weird how you just write better code when you stop to think what you really want it to do first.

Comments

Where’s Wes?

By the Firelight

It has been quite some time since I have found time to sit and write. Quite a bit has happened, since I last dumped myself to the internet. As a result, this is going to be all over the place, and very shallow

  • Auntie Nene, and Uncle Ed came by the abode on either end of their vacation. It was a nice visit, and either they enjoyed themselves, or they faked it very well. I'll be able to tell if they ever come back
  • The yard looks completely different. We finished the raised garden and have it planted. Furthermore, the three yards of loam that we picked up is either in the garden, or is spread around the yard. It was about as much fun as...well spreading around three cubic yards of loam can be. We have seeded the grass a couple times, and how have a million green little spear heads poking out of the ground. Soon the lawn will be thick and green and I'll be sick of cutting it.
  • I purchased a motorcycle. I purchased a 2003 Buell XB9S, and am absolutely loving it. I got the bike at a great deal considering how rare it is, and all it needs was a little love. I've already changed out the motor and fork oil, I'm equipped to change out the transmission oil, and all that will be remaining is a new set of tires. I managed to survive all the "I'm going to buy a black dress and wait for the police to call" jokes from the women in my family, and now have rekindled the love I have for riding.
  • I'm nearing the end of my MCPM course. We just finished the eighth session, and only have the final session and the simulation remaining. I've learned a boat load, and wished that I had taken the course before I was given actual projects to manage, but I'm still very glad that I'm taking it now. Although it will be very nice to once again take control of my weekends and not have to sacrifice a half here and a half there.
  • Changes are brewing professionally. One of my secondary incomes has changed some of the rules, thus making it much less appealing. After much internal debate, I'm moving more effort into the third, ditching the second, and adding a new one. If you know me well, you know what I'm talking about. If you don't, why not pick up the phone now and again?
  • We went out camping to Old Man River on the long weekend. As is usual with car-camping, a lot of time was spent in setting up camp (which I termed: Tarp City by weekend's end), and way-way-WAY too much time cooking and eating food next to the campfire. The weather was really co-operative, and I'm getting excited to do more camping and backpacking throughout the summer.
  • I picked up a Water Rower and have been rowing odd morning to get back into a better shape. I'm in shape, but right now it's more 'tube-steak' than 'chiselled-rock'. I managed to get a discount from the sales guy, but Fed-Ex evened the score with the largest shipping bill I've ever had. It wasn't a heavy package, but the rails are seven feet long, and I guess that's hard to stack up. So far, I love it. It's quiet, sturdy, and quite a nice looking piece of hardware.

The next few days are looking to be hectic as well: Another MCPM session, a Smashening, motorcycle maintenance, yard work and a 'sales meeting' have to slide in around the day job, sleeping and eating before the next weekend is finished.

Comments

Photo Friday: Smoke

I smell burning

This week's Photo Friday challenge was of the variety where one could have a multitude of photographs that fit the category. I decided the second I read it that I would create a new image for this challenge, and after a few hours in my basement with the incense burning, the strobe firing and me wafting at a trail of smoke I captured this image. A little bit of photoshop later, and this was the final result.

Comments

Plumbing was invented by the Devil

Bankers hall from the Calgary Tower

I was bit by one of those jobs that was expected to take just a couple minutes that ended up spanning what seemed to be a lifetime. Sunday, my sole day of freedom, was going to be spent tightening up some odd ends, and then wasting the evening unwinding in front of the television. Life, it turns out, had other plans.

Some of the work I had done while I still had a renter, had started to leak. It wasn't a major leak, and the water from the leak flowed straight into the drain in the floor. Thus, it did not rate very high on my list of things to get done right now. Nevertheless, it started to move it's way to the top of the 'Honey-Do' list, and on a wonderful sunny Sunday afternoon I started the job that was supposed to take ten minutes.

The leak was at a junction of old and new, where easy-happy-go-lucky polyethylene pipe ran into a T-intersection where the other two inhabitants were of the OMG-I-can't-believe-this-is-so-hard-and-dangerous copper piping. I deduced, incorrectly, that the leak was where the PEX met the copper T-pipe. Thus, I purchased a high power pipe clamp, and was going to clamp that little white pipe onto that copper and be done with it. It turns out, much after the fact, that the leak was not between the PEX and the copper, instead it was in the solder holding the 1/2" PEX fitting into the T-intersection. Of course, as I cranked on that high power pipe clamp, I was very minutely decreasing the diameter of the old-new fitting, and as a result, was destroying even more of the delicate solder bond.

Now, I had a real leak.

I was quick to figure out that the T-intersection was going to have to be replaced, and I was going to have to do it right now. A trek to Home Depot was required, and I filled up on all sorts of elbows, pipe cutters and a few short chunks fo pipe.

I guess this is where I should explain why I absolutely hate plumbing. I do have all the skills to fill that classification. Plumbing requires cutting, I know how to cut; Plumbing requires soldering, I know how to solder; Plumbing requires crimping, I even know how to crimp. After that as long as you understand gravity, you can pretty much handle the majority of plumbing cases. The difference is in the context.

Plumbing is always done in the wrong environment. Sure, you can cut a pipe, but if you are dealing with existing plumbing, there is usually something inside. I also hate working when I'm wet. The soldering is also done in an entirely different way. I'm used to the electronic variety, where all you need to do is make an electronic connection and you need to use soldering iron. The principles are close, but in plumbing you are in essence filling a gap with solder and blow torch. The last part is where ALL the fun is. If you don't get everything just right you have liquid metal jumping off of cold copper, right onto you arms and hands.

I was full speed into the replacement of some of my plumbing, when I just couldn't get a fitting to join with the copper. I was starting to get frustrated, when I reached the end of my solder. Great. And, the time was 8:30; right after everybody closes up for the night on Sunday. A little brainstorming, and we came up with going to the pinnacle of retail: Wal-mart.

I was again armed with materials, and back to work. I worked up until 10:30, when I had soldered the last joint, and crimped the last end of PEX, it was go time. I was looking forward to a nice warm shower, and going to bed. I cranked on the main, and watched in horror was water poured out of my T-intersection, and a couple of my soldered joints. Tired, and fed up I went to bed anyway.

Today, I took the second half of the day off, and armed myself once again at the Home Depot. First order of business: rip out everything that leaked, and start anew. I found that today I had much more success, due to being more relaxed, and knowing what I was getting into . I spent more time preparing, and less cutting corners and in the end, after hours of RE-work I cranked on the main, and was rewarded with no leaks. I'm sure my co-workers will appreciate the shower tomorrow.

Comments