On Sun, Sep 20, 2009 at 9:34 PM, nruth <nick.rutherf...@gmail.com> wrote:
>
> We're using a describe (or context) block to name (or document) a
> state, then using a separate before block to set up that state
> (context). If that before block were to go astray the documentation
> would cease to be correct.

On further reading and thinking, I think I might see some of the
confusion.  You're not quite correct that the describe and the before
are "separate blocks."  The before block lives *inside* the describe
block, and composes part of what is described.

The describe block is more than "documentation."  It's a class
definition.  (Literally.)  Class definitions do more than just provide
names; they bundle up behavior.  The before block can (not literally,
but effectively) be considered as a sort of constructor method for the
class, similar to 'def initialize' in a non-RSpec class but with more
chaining built in.  Nested example groups are subclasses that invoke
the superclasses's constructors automatically, etc.

This is all very clean, mostly traditional object-oriented language
behavior.  Your suggestion of putting the initializer as a block value
to a hash option is more complicated; it's like saying normal Ruby
classes should not have an 'initialize' method, but instead should be
declared like 'class Foo :constructor => lambda{initializer code
here}'.  Ruby's insistence that you should call 'new' but implement
'initialize' is confusing enough.  The lambda-option style doesn't
make it clearer.

Does that make sense?  "Describe" and "before" aren't disconnected
entities.  They're body and organ.  One is a part of the other.


-- 
Have Fun,
   Steve Eley (sfe...@gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to