[Rspec-devel] self naming specs

David Chelimsky dchelimsky at gmail.com
Fri Mar 31 20:32:22 EST 2006


Guys, I started looking at the self-naming spec idea and there's a few
complications that make me wonder whether it's really feesible. Let me
know what you think:

First, let's imagine a spec like this:

context "An empty stack" do

  setup do
    @stack = Stack.new
  end

  specify do
    @stack.should.be.empty
  end

  specify do
    @stack.size.should.be 0
  end

end

What we'd want this to produce would be this:

An empty stack
- should be empty
- size should be 0

The problem is that the should helper has know way of knowing
definitively whether its caller is the subject of the context (the
stack) or something else, like the Fixnum resulting from @stack.size.
We could, conceivably do something like this:

context "An empty stack" do
  subject @stack = Stack.new
  ...
end

but then we start adding confusion to reduce the duplication. The
self-naming spec would be a cool feature, but right now things are
very, very clean. I don't want to fuck that up.

Thoughts?



More information about the Rspec-devel mailing list