[rspec-users] Help with controller spec?

Matt Darby matt at matt-darby.com
Tue Jan 6 10:53:12 EST 2009


I'm stumped. How would I go about specing the "update_sandbox" method?

# bids_controller:
   def new
     @bid = Bid.new

     respond_to do |wants|
       wants.html { redirect_to job_bids_path(@job) }
       wants.js {
         update_sandbox do
           render_to_string :partial => 'new', :locals => {:bid =>  
@bid, :job => @job}
         end
       }
     end
   end


Here is my 4789th stab at it:

# bids_controller_spec.rb
     it "should render new template" do
       sandbox = mock("Sandbox")
       controller.stub!(:update_sandbox).and_return(sandbox)
       sandbox.stub!(:render_to_string).with(:partial =>  
'new', :locals => {:bid => @bid, :job => @job})

       sandbox.should_receive(:render_to_string).with(:partial =>  
'new', :locals => {:bid => @bid, :job => @job})
       controller.should_receive(:update_sandbox)

       xhr :get, :new
     end

# => Mock 'Sandbox' expected :render_to_string with  
({:partial=>"new", :locals=>{:job=>#<Job:0x2b497e8  
@name="Job_1014">, :bid=>#<Bid:0x2b46f0c @name="Bid_1015">}}) once,  
but received it 0 times

Any pointers would be greatly appreciated!



Thanks!

Matt Darby, M.S.
Rails | PHP | Linux | MySQL | IT

Email: matt /\at/\ matt-darby.com
Skype: matt-darby
Web: http://blog.matt-darby.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090106/d2eed459/attachment.html>


More information about the rspec-users mailing list