[rspec-users] Rspec Caveman questions.

Scott Taylor mailing_lists at railsnewbie.com
Sat Sep 8 16:46:52 EDT 2007

On Sep 5, 2007, at 3:49 PM, sudara wrote:

> Hello!
> I'm just a caveman with some caveman questions.
> I've been parsing Rspec for quite a while, and I'm writing my first  
> series
> of specs. My initial impressions are "Verbose, but understandable.  
> Helpful
> and intuitive, but so much to digest." I want to congratulate the  
> folks who
> are dedicating a chunk of their lives to writing this, and ask 2  
> caveman
> questions
> My first is "Why lambda in rpsec"? It doesn't strike me as "reads like
> english" or "easily understandable." I understand it's place in  
> ruby (um,
> kind of :), but my thinking is:
> lambda { do_something_risky }.should raise_error
> would be more understandable (and fun!) written as:
> running { something_risky }.should raise_error

It's not too hard to understand is it?  Lambda/Procs are used for  
delayed evaluation.  If you did something like this:

do_something_risky.should raise_error,

then an error would be raised even before the should method could be  
called to check for an error.

The beauty of ruby is that if you really wanted "running", it would  
be rather easy to add it yourself:

alias :running :lambda

> My second question is: For those folks who are getting up to speed  
> with ruby
> and rails AND digesting rspec along the way, there is a lot of  
> incoming DSL.
> As I started with rails before rspec, I found myself using script/ 
> console to
> check my code, poking at different ways of expressing myself with  
> ruby.
> Is there a way to "poke at my specs"? I can load up my test  
> environment, but
> can I spec things "live" so that I can find out what works and what  
> doesn't?
> I find I'm wasting a chunk of time (as I don't have the DSL even  
> 60% down)
> writing specs and getting it wrong. Am I missing a trick, or  
> I.should_have
> dsl_down_before_trying.else_return(crying)?

Honestly, If you are used to Test::Unit, the difference is mainly how  
you assert:

assert_equal obj, value

obj.should == value

You might also want to look at my last email about custom matchers +  



More information about the rspec-users mailing list