[rspec-users] Help with controller spec?

Matt Darby matt at matt-darby.com
Tue Jan 6 11:41:48 EST 2009


On Jan 6, 2009, at 11:27 AM, David Chelimsky wrote:

> On Tue, Jan 6, 2009 at 9:53 AM, Matt Darby <matt at matt-darby.com>  
> wrote:
>> 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)
>
> I'm just guessing here, because I don't know what #update_sandbox
> does, but you probably want this to yield the sandbox:
>
> controller.should_receive(:update_sandbox).and_yield(sandbox)
>
> Let us know if that works.
>
> Cheers,
> David
>

Unfortunately, I get the same result. Here is the #update_sandbox  
method:

# application.rb
     # RJS method to show new / edit partials
     def update_sandbox(obj = nil, &block)
       highlight_this_div = obj ? dom_id(obj) : :sandbox

       render :update do |page|
         page[:error_div].hide
         page.replace_html :sandbox, capture(&block)
         page.visual_effect :scroll_to, :sandbox
         page.visual_effect :highlight, highlight_this_div
       end
     end


Thanks for your help David!



>>
>>      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
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list