[rspec-users] (no subject)

David Chelimsky dchelimsky at gmail.com
Thu Jun 21 10:26:15 EDT 2007

On 6/21/07, Tom Locke <tom at hobocentral.net> wrote:
> Hi,
> Not sure if this is the right place for general questions on BDD
> style, but here goes...
> I have a class which behaves almost like a big function - you always
> instantiate it with a bunch of args, and call one of a couple of
> methods to get the results back.
> BDD style seems to like a separate describe block for each
> instantiation of the class under test.

Only when you're describing that object in different starting states.
If there's only one starting state, you can create one of them
before(:each) example:

before(:each) { @thing = Thing.new }

> In this case that would mean a
> ton of describe blocks, each with just one it "..." do block
> (terminology??). That seems rather verbose. What would the
> recommended style be?

If you need the object in different starting states, you've got a few
options. You could go w/ the context approach you described above in
which you have a different description for each starting state.

You could also make a helper method (or a couple of them) in a module:

module ExampleHelpers
  def create_thing

describe "Stuff" do
  include ExampleHelpers
  before(:each) { @thing = create_thing }

Another is to use a shared behaviour:

describe "All Things", :shared => true do
  before(:each) { @thing = Thing.new(with, a, bunch, of, args) }

describe "One Thing" do
  it_should_behave_like "All Things"
  # now you can access @thing in each example

> And the meta question - where should I go to educate myself on this
> stuff?

This is a good place. Here are some blogs:


Another list is testdrivendevelopment at yahoogroups.com. BDD started off
as TDD with more focus on behaviour, but serious TDD'ers (who live on
that list) know better (they were already focusing on behaviour).


> Thanks
> Tom
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list