[rspec-users] catching errors, rspec basics
Andrew WC Brown
omen.king at gmail.com
Tue Jan 29 23:12:52 EST 2008
So if I understand correctly,
The following didn't raise an error:
@audience.stats = 'Market Goblin'
@audience.stats.should raise_error
because audience.stats didn't return an error.
Where as lambda will return an error.
On Jan 29, 2008 10:58 PM, Ben Mabey <ben at benmabey.com> wrote:
> Andrew WC Brown wrote:
> > ohhhhh, I left in:
> >
> > it "should return an error when passed a string" do
> > @audience.stats = 'Market Goblin'
> > lambda {@audience.stats = 'Market Goblin'}.should raise_error
> > end
> >
> > when yours is:
> >
> > it "should return an error when passed a string" do
> > lambda {@audience.stats = '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 {@audience.stats = '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 at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/7fcdaa98/attachment-0001.html
More information about the rspec-users
mailing list