[Rspec-devel] Skeleton Generator

Judson Lester nyarly-rspec at redfivellc.com
Mon Aug 14 16:56:51 EDT 2006

David Astels wrote:
> On 11-Aug-06, at 8:30 PM, Judson Lester wrote:
>> context "A fresh pack of cards" do
>>   setup do
>>     @deck = Deck.new(52)
>>   end
>>   specify "should be shuffleable" do
>>     @deck.shuffle
>>   end
>> end
> First of all, this makes no statement about behaviour.  All that it  
> is doing is sending the "shuffle" message to @deck.  No behaviour is  
> being specified.  What is the result or side-effect of Deck.shuffle?
> Also, nothing is said about the purpose/meaning/value of the argument  
> to Deck.new.  What happens for Deck.new(0)?  Deck.new(104)?
Fair enough.  I was writing to my concept rather than as a real spec.  
Should have been obvious at the end where against the generated code 
there were no failures.

Swap in this:

  specify "should have 52 cards" do

with a corresponding generated Deck#size method.  Then the result is 
that the code gets generated, and there's a failure, because @deck.size 
doesn't return 52.
> There is no failing specification/example/test/anything, therefore  
> there should be no code.  The whole idea is that you write a tiny bit  
> of spec... just enough to fail because the required behaviour does  
> not exist.  Then you write just enough code to satisfy the spec that  
> is failing.  How is having automated generation of any help?
There isn't a human-involved iteration of "NoMethodError: size"

There's less room for human error - because you only typed in the method 
name once.  (Granted, there's room for automatic error, if you reference 
a method twice in spec and misspell it the second time...)

Generally, my thought is this is a corollary to the philosophy that 
testing should be as automatic as possible.


More information about the Rspec-devel mailing list