<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:garamond,new york,times,serif;font-size:12pt">OK, I see your strategy now. Rather than mock the String argument, mock Order to confirm that it gets called with an array. Nice!<br><br>Al<div><div style="font-family: garamond,new york,times,serif; font-size: 12pt;"><br><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: Jarkko Laine <jarkko@jlaine.net><br>To: rspec-users <rspec-users@rubyforge.org><br>Sent: Tuesday, December 4, 2007 1:49:17 PM<br>Subject: Re: [rspec-users] params not available for controller specs?<br><br>
<br>On 4.12.2007, at 23.11, Al Chou wrote:<br><br>> I think Jarkko is saying that no spec should have been written for <br>> the code I was trying to fix/change. I'm not sure I would agree <br>> that BDD/RSpec is an inappropriate tool for documenting what I was <br>> trying to change, but I think he would argue that....<br><br>What I was saying was that I think it's important that Order.find gets
<br>called with an array of ids. That's what you want to happen and to <br>have in your spec, right? So in your spec, you'd have<br><br>it "should find orders with an array of ids" do<br> Order.should_receive(:find).with(["1", "2", "3"])<br> get :download, :ids => "1/2/3"<br>end<br><br>(or whatever ids you pass to the action).<br><br>Now, if the current, buggy behaviour just passes the string as "1/2/3"
<br>to Order.find, the spec above will break, because it will not receive <br>an array but a string. After you add the split("/") call to the actual
<br>code, your broken spec is fixed, and the code works as expected. Tada!
<br>No need to stub String#split anywhere.<br><br>//jarkko<br><br>--<br>Jarkko Laine<br><a href="http://jlaine.net" target="_blank">http://jlaine.net</a><br><a href="http://dotherightthing.com" target="_blank">http://dotherightthing.com</a><br><a href="http://www.railsecommerce.com" target="_blank">http://www.railsecommerce.com</a><br><a href="http://odesign.fi" target="_blank">http://odesign.fi</a><br><br><br>_______________________________________________<br>rspec-users mailing list<br><a ymailto="mailto:rspec-users@rubyforge.org" 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></div></div></div></div><br>
<hr size=1>Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs"> Make Yahoo your homepage.</a>
</body></html>