[rspec-users] RJS specs

Ashley Moran work at ashleymoran.me.uk
Tue Feb 13 09:51:50 EST 2007


Hi again...

This is wierd spec problem no. 3.  I've got a simple one line RJS  
file that renders a partial specified by the controller
     page.replace_html("product_info", :partial => @product_partial)

The partials in question will contain purely static content - the  
idea is to have some dynamic links, so you hit
   http://localhost:3000/gap/product_info/product_1
   http://localhost:3000/gap/product_info/product_2

it will render _product_1.rhtml, _product_2.rhtml in a div etc.

Ideally I'd like to write something like:

   page.should_receive(:replace_html).with("product_info", "product_1")


So far the best I can find is to add a div with a known id to each  
partial and test like this:

     context "A rendered gap/product_info" do
       specify "should have RJS to update the product_info div" do
         assigns[:product_partial] = "product_info_rti"
         render 'gap/product_info'

         response.should_have_rjs :replace_html, 'product_info'
       end

       %w[ rti finance ].each do |product_type|
         specify "should have a product_info_#{product_type} div when  
the " do
           assigns[:product_partial] = "product_info_#{product_type}"
           render 'gap/product_info'

           response.should_have "div#product_info_#{product_type}"
         end
       end


     end


It's far from ideal, because it relies on someone remembering to  
update the spec if a new product type is added.  I can't see a more  
direct way to test the RJS though.

Thanks
Ashley


More information about the rspec-users mailing list