Andrew WC Brown wrote:
> ohhhhh, I left in:
>
>   it "should return an error when passed a string" do
>     @audience.stats = 'Market Goblin'
>     lambda [EMAIL PROTECTED] = 'Market Goblin'}.should raise_error
>   end
>
> when yours is:
>
>   it "should return an error when passed a string" do
>     lambda [EMAIL PROTECTED] = 'Market Goblin'}.should raise_error
>   end
>
> I've seen lambda before but not sure what it does.

A lambda in ruby is like a block or a Proc.  There are some differences 
between them, but for this simple use you can just think of it as a 
block of code that will be passed to the 'raise_error' matcher that then 
runs that block of code checking to see if an Exception is raised when 
it is ran.  You can also pass in the specific exception type to be more 
specific. 

As  a personal preference I like to alias lambda to 'running' in my 
spec_helper.rb... I think this reads a lot better:
running [EMAIL PROTECTED] = 'Market Goblin'}.should raise_error

For more on lambdas refer to the pickaxe.  If you want more detailed 
information of the subtle differences between them, Procs, blocks, and 
methods check this out:
http://innig.net/software/ruby/closures-in-ruby.rb

-Ben


_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to