Friday, May 05, 2006

Back to Checkr and RSpec

In my last post on RSpec, I talked about cleaning up the stacktrace and exception thrown by the specification that I'd written. It turns out that this is all according to the design of RSpec, and the only way I'm going to get things cleaned up is to write some code to make things work — fortunately this is pretty easy to do. All we'll need to do is add a baz method to our Foo class, like so:

  def baz

Once we've done this, we're able to rerun our spec file, and everything looks good:

spec rspec_foo.rb
Finished in 0.000429 seconds
1 context, 2 specifications, 0 failures

None of this really feels like I'm testing behavior though, it's all pretty much normal TDD style test code. I'm going to junk the whole thing, and see if I can't make a better go of it. Before I start though, it probably makes sense to understand why I'm looking at RSpec for checkr.

When Sean and I talked about BDD, he identified three things that he felt were more in line with his thinking:

  • We're specifying behavior instead of state.
  • Creating smaller units of specification increases the cohesion of tests while decreasing coupling between them.
  • There's no link between program and test structure.
If I go to work with these three things as my goals I should be able to get to an rspec file that does what we want. My new plan is to grab each test in test_check.rb, determine what behavior it's trying to test, and write a specification for that. I should be able to start that on Monday.

1 comment:

Sean said...

I can't wait to see what you come up with. My furtive attempts to learn rspec have not achieved much. It is hard to overcome the momentum of my reliance on things like autotest.