On 17/08/06, <b class="gmail_sendername">John Wilger</b> <<a href="mailto:johnwilger@gmail.com">johnwilger@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
First, thanks for releasing Mocha. As someone who's been practicing<br>TDD much longer than I've been using Rails, one of my biggest<br>complaints has always been the fact that the "Unit" tests are more<br>like intefration tests because of how tightly coupled the domain model
<br>is when using ActiveRecord. Stubba looks like it could really help<br>aleviate this problem.</blockquote><div><br>Thanks. This was pretty much the reason for creating Mocha (and Stubba).<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
def test_import_should_create_product_when_it_does_not_exist<br> Product.stubs( :create ).with( expected_arguments ).times( 1 )<br> Product.import( import_line )<br> end<br><br>I would expect that to either a) raise an exception because it's
<br>invalid or b) fail the test since the implementation of Product.import<br>does not currently call Product.create. Instead, the test passes.<br><br>Any ideas how I can make this work as expected?</blockquote><div><br>If you want to assert that "create" is called, all you need to do is change "stubs" to "expects"...
<br><br><span style="font-family: courier new,monospace;">def test_import_should_create_product_when_it_does_not_exist</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
Product.expects( :create ).with( expected_arguments ).times( 1 )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Product.import( import_line )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">end</span><br style="font-family: courier new,monospace;"><br>As long as you are using the latest (0.2) version of Mocha, this expectation should be auto-verified.<br><br>
If not, just add a line at the end of the test: <span style="font-family: courier new,monospace;">Product.verify</span><br><br>Expectations are verified, stubs are not. Does that make sense?<br><br></div></div>James.<br><a href="http://blog.floehopper.org">
http://blog.floehopper.org</a>