[rspec-users] params not available for controller specs?

Al Chou hotfusionman at yahoo.com
Tue Dec 4 21:21:07 EST 2007


OK, I see your strategy now.  Rather than mock the String argument, mock Order to confirm that it gets called with an array.  Nice!

Al

----- Original Message ----
From: Jarkko Laine <jarkko at jlaine.net>
To: rspec-users <rspec-users at rubyforge.org>
Sent: Tuesday, December 4, 2007 1:49:17 PM
Subject: Re: [rspec-users] params not available for controller specs?



On 4.12.2007, at 23.11, Al Chou wrote:

> I think Jarkko is saying that no spec should have been written for  
> the code I was trying to fix/change.  I'm not sure I would agree  
> that BDD/RSpec is an inappropriate tool for documenting what I was  
> trying to change, but I think he would argue that....

What I was saying was that I think it's important that Order.find gets
  
called with an array of ids. That's what you want to happen and to  
have in your spec, right? So in your spec, you'd have

it "should find orders with an array of ids" do
   Order.should_receive(:find).with(["1", "2", "3"])
   get :download, :ids => "1/2/3"
end

(or whatever ids you pass to the action).

Now, if the current, buggy behaviour just passes the string as "1/2/3"
  
to Order.find, the spec above will break, because it will not receive  
an array but a string. After you add the split("/") call to the actual
  
code, your broken spec is fixed, and the code works as expected. Tada!
  
No need to stub String#split anywhere.

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


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





      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/b0971fe6/attachment.html 


More information about the rspec-users mailing list