[Rspec-devel] Skeleton Generator

Judson Lester nyarly-rspec at redfivellc.com
Fri Aug 11 19:30:58 EDT 2006

Steven R. Baker wrote:
>> What I'd been considering working on under Test::Unit (and was  
>> dissuaded
>> by it's byzantine internals) was a skeleton code generation tool.   
>> Short
>> form: write your specs with the knowledge that they'll fail.  The spec
>> runner catches NameError and NoMethodError and starts constructing the
>> basic skeleton of actual classes, until specs fail for other reasons.
> I think a tool to do this for Test::Unit is already in ZenTest.  I  
> know there's one that goes the other way.
On reflection, I'm sure there is.  In fact, zentest takes a switch to do
the generation.  The basic difference between ZenTest and what I'm
considering is this: ZenTest essentially performs a textual conversion
between TestClass names and Class names.  So TestA::TestB#test_amethod
<=> A::B#amethod.  Which is fine, as far as it goes.
>> The driving motivation here is the same as automated testing: the  
>> easier
>> it is to do, the more I'll do it.  And if I can get the class and  
>> method
>> definitions started for the price of writing starter specs, not  
>> only is
>> it easier (because I cut out the "write the class defs to that the  
>> test
>> doesn't fail there" steps) , but I actually get work done for me.   
>> Time
>> profit!
>> Now, I anticipate that there'll be a bunch of spongy problems to solve
>> in attempting this, but the reason I post the idea here is: is this
>> something the the larger community would be interested in, and  
>> might it
>> have a home in rspec eventually?
> This is probably a desirable feature for many would-be users, but it  
> really defeats the purpose of what we're trying to do.  It removes  
> the "Driven" part.  If you're writing more than one spec/example/ 
> behaviour at a time, then you're writing code to make more than one  
> pass.
Perhaps there's a philosophical point I'm missing, and it would probably
be enlightening to me (and maybe others) if you could show me where I'm
going wrong.  Let me make an example:

I write the following:

context "A fresh pack of cards" do
  setup do
    @deck = Deck.new(52)
  specify "should be shuffleable" do

And the following is generated:

class Deck
  def initialize(number)

  def shuffle

Now I can review the generated code, and then add specify blocks to my
spec file in order  to drive development.

What purpose does this defeat?


More information about the Rspec-devel mailing list