You can get the video version of this podcast here.
David Heinemeier Hansson sparked a debate on Twitter about Ruby testing frameworks. A lot of people saw it as slamming RSpec and others saw it as constructive conversation about what tools you use and why. This is how I view to see it and where I come down on this debate.
I also discuss why we have these debates in general and what we can learn from them.
Because I’m going to be testing in cucumber sections of the site that require a user to be logged in, I decided to get it out of the way. So, in this video, I write a cucumber feature to test login and round it off with a few tests on the devise generated user model to make sure it continues to behave as I expect it to as I update it throughout the process of building this application.
I was setting up a new project/gem that interfaces with Project Honeypot. While I was setting it up, I ran into a couple of problems running my specs. The first one, I hit this error while running ‘bundle exec spec spec’:
/usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.2/lib/bundler/shared_helpers.rb:137:in `bin_path': can't find executable spec (Gem::Exception)
What this means is that the spec gem doesn’t have an executable called ‘spec.’ This confused me since all of the previous versions had been run with a ‘spec’ command. As it turns out, in RSpec 2.0.x, the command to run your specs is ‘rspec,’ not ‘spec.’ So a ‘bundle exec rspec spec’ got around that error.
The next issue I got was an undefined constant error for ‘Spec::Runner.’ Here is my spec_helper where I was referencing Spec::Runner.
require File.dirname(__FILE__) + "/../lib/project_honeypot"
Spec::Runner.configure do |config|
So, RSpec has changed the configuration setup to use RSpec instead of Spec::Runner and it worked like a charm.
Every good project needs a good setup. In this episode, I set up a github repo, create a new rails application, hook in Cucumber and Rspec, write a Cucumber feature, and write the code to make it pass. Download 142 MB Download (iphone & ipod) 59 MB
RSpec gives us many powerful tools to make our tests readable. Matchers allow us to provide custom predicates to our should statements that succinctly define the behavior of our code. Download 27 MB Download (iphone & ipod) 14 MB
RSpec provides an extremely concise way of representing simple tests to be called on new instances of a class or on explicitly defined receiver objects. You can do this by using ‘subjects’ either as defined by the ‘describe’ or the ‘subject’ methods. Download 38 MB Download (iphone & ipod) 18.2 MB
Test Driven Development and Behavior Driven Development can be terrific tools in defining your code and ensuring the highest quailty software. In this episode, we discuss the differences between TDD and BDD and what the advantages are to doing them.