Last week in 4 sentences or less:
I hate that the ruby community still works against each other in more ways than they collaborate. Rspec2 is great, it fixes a ton of problems I have had with Rspec for a while, but getting it working on any of my development machines with Rake proved to be more for me than I was willing to take on. C is a really cool language from five thousand years ago and we need a more modern compiled language that brings in younger talent. I LOVE the orange sauce from this recipe.
Now on to re-learning all of the memory tuning settings for an optimally tuned mysql machine, then writing an algorithm to make a config file based on the amount of system ram available at startup.
There are very few things in life that I like more than sitting down and writing some code. I don’t claim to write good code, but I like to write it nonetheless. One thing that I have begun doing and learning is Behavior Driven Development (BDD) using RSpec.
For some time now I have made it a point to make unit tests for my code. If you’re like me you tend to get lazy and write the tests after the code and then you get into some hellacious debugging issues. I *think* that this was mainly because I thought of unit tests as just a simple way of verifying that each method worked in my code. So testing became cumbersome and just a little bit confusing. With BDD and RSpec I actually have found it easier to think of my code in what most in the industry call “user stories”. I like to kick things up a bit so I call them “user adventures”.
Once you know your story/adventure it is easy to write the behavior out in a spec file that tests the functionality of the end result of your code. Thus making the inner workings less important and therefore doesn’t require too much thought process to get a basic test suite working.
As I started to use RSpec more I found that I really liked the process and felt it necessary to include it in all my coding endeavors. A few days ago I decided it was time to do a sweeping gem update to bring my rubygems current. Without giving it much thought I inadvertently updated my rspec gem to the current 2.x release which completely broke my test suites due to some namespace changes.
Once you start developing multiple file applications/utilities you end up with a dozen or more spec files and you want/need an easy way to run all tests to verify that your code is good to go. In comes the handy Rakefile. RSpec has always had great integration with Rake and therefore most people have been using rake to integrate their tests with their development environment. It is much easier to run “rake test” or just “rake” than to write some bash foo that iterates through a directory and runs spec/rspec on all files ending with _spec.rb.
It is this integration I wanted to document here on my blog more for my purposes but in the off chance someone else stumbles here maybe they will have an easier time getting what they need out of it.
This will not turn into a howto on BDD because frankly I am self taught and I don’t think I know it well enough to say you should take lessons out of my book. The examples below are pulled straight from the RSpec website here.
First and foremost, you need to have a directory in your project root called “spec”. The name is inconsequential as long as you know what you are doing but it is easiest to follow convention as most tools use this as default. Within that directory you will create test files, again convention says you will name it after the story/adventure you are trying to model.
Here is a sample:
describe "something" do it "does something" do # pass end end
And then in the root of your project would lie your Rakefile, named “Rakefile”. Below is the code used to run all tests as the default task when rake is run and that tasks job is to run all files in the spec directory as rspec tests.
require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task :default => :spec
Now when you are at the command line in the root directory of your project you will be able to run “rake” and all tests run and you will see if your behavior is appropriate and immediately see if changes you have made in your code since the last tests were run has affected anything.
Thanks for looking, I know there is very little meat and potatoes here but check out RSpec. You might find that it makes your development efforts easier in time.
Or do you? For quite some time now I have had this sinking feeling in my stomach. While laying in bed last night, unable to sleep, I had an epiphany. I have grown stagnate, content and comfortable in my professional life. I began to recall the days of burying my head into a problem and the sweet exhaustion I felt when I finally figured it out. Then I asked myself where that feeling has been and the answer was right in front of me. Like many around me at work, I was comfortable with what I knew and lost the drive to learn more. I took on only the problems I knew I knew how to fix and thus my days began to drag. I went from looking up at the clock only to find I should have eaten lunch 5 hours ago to staring at the clock, waiting for my day to end.
In the last eleven years at my current employer I have learned one very important thing, you *have* to help yourself. So I am taking it upon myself to make a change. For lack of any real creativity I am going to call it “Learn Something New Everyday”. Maybe this movement stays with me, maybe it goes further, but as long as I stick with it I think I will feel better about myself and thus feel more reward at the end of the day.
The gist of this change is to make a conscious effort to learn or relearn something each day at the start of the day. This will stimulate the brain and spur more thoughts for new things to learn throughout the day. From now until eternity I am going to carve out the first hour of my day to dig into something and learn what it is, what it does what makes it work. Some of these things I will blog about to share with my committed 3 readers and one comment spammer who desperately wants to sell you some Viagra and Cialis.
As a study I will also make an effort to document my feelings to see if this change helps at all. Hell, I may realize I am just a lost cause and I should just be content with life but something tells me different.
I will start today off with learning how to integrate RSpec 2 with Rake and I am feeling cautiously optimistic.
You might recall seeing a post from me a few years ago with an xray showing a plate and screws. During my second surgery my doctor felt like the bone had grown in sufficiently so he took out my old plate. Here it is.
Well I knew it was too good to be true. My last back surgery was a great success for one of my bad discs. We had hoped that would allow my other bad disc to heal but alas hoping and reality are seldom the same. I have suffered a complete rupture of another disc and have to get surgery again. June 18th is the day. Send me all the prayers you can please, I need them.