So if I understand correctly,<div><br class="webkit-block-placeholder"></div><div>The following didn&#39;t raise an error:<br><div><br class="webkit-block-placeholder"></div><div><span class="Apple-style-span" style="border-collapse: collapse; ">@audience.stats = &#39;Market Goblin&#39;</span><br>
</div><div><span class="Apple-style-span" style="border-collapse: collapse; "><div>@audience.stats.should raise_error</div></span><div><br class="webkit-block-placeholder"></div><div>because audience.stats didn&#39;t return an error.</div>
<div><br class="webkit-block-placeholder"></div><div>Where as lambda will return an error.</div><br><div class="gmail_quote">On Jan 29, 2008 10:58 PM, Ben Mabey &lt;<a href="mailto:ben@benmabey.com">ben@benmabey.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Andrew WC Brown wrote:<br>&gt; ohhhhh, I left in:<br>&gt;<br>&gt; &nbsp; it &quot;should return an error when passed a string&quot; do<br>
&gt; &nbsp; &nbsp; @audience.stats = &#39;Market Goblin&#39;<br>&gt; &nbsp; &nbsp; lambda {@audience.stats = &#39;Market Goblin&#39;}.should raise_error<br>&gt; &nbsp; end<br>&gt;<br>&gt; when yours is:<br>&gt;<br>&gt; &nbsp; it &quot;should return an error when passed a string&quot; do<br>
&gt; &nbsp; &nbsp; lambda {@audience.stats = &#39;Market Goblin&#39;}.should raise_error<br>&gt; &nbsp; end<br>&gt;<br>&gt; I&#39;ve seen lambda before but not sure what it does.<br><br>A lambda in ruby is like a block or a Proc. &nbsp;There are some differences<br>
between them, but for this simple use you can just think of it as a<br>block of code that will be passed to the &#39;raise_error&#39; matcher that then<br>runs that block of code checking to see if an Exception is raised when<br>
it is ran. &nbsp;You can also pass in the specific exception type to be more<br>specific.<br><br>As &nbsp;a personal preference I like to alias lambda to &#39;running&#39; in my<br>spec_helper.rb... I think this reads a lot better:<br>
running {@audience.stats = &#39;Market Goblin&#39;}.should raise_error<br><br>For more on lambdas refer to the pickaxe. &nbsp;If you want more detailed<br>information of the subtle differences between them, Procs, blocks, and<br>
methods check this out:<br><a href="http://innig.net/software/ruby/closures-in-ruby.rb" target="_blank">http://innig.net/software/ruby/closures-in-ruby.rb</a><br><br>-Ben<br><br><br>_______________________________________________<br>
rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>
</blockquote></div><br></div></div>