[rspec-users] [RSpec][RJS] Problem with specing create.rjs in controller_spec

Nick Hoffman nick at deadorange.com
Thu Feb 26 16:46:42 EST 2009


On 26/02/2009, at 11:25 AM, David Chelimsky wrote:
> On Thu, Feb 26, 2009 at 10:01 AM, Evgeny Bogdanov
> <evgeny.bogdanov at gmail.com> wrote:
>> Could somebody please explain me what I am doing wrong.
>> I am trying to spec create.rjs file, that is returned from my
>> controller.
>>
>> render_template("create.rjs") works just fine,
>>
>> however have_rjs fails with the following error:
>> 'CommentsController while posting a comment renders a create.rjs
>> template when comment is successfully created in ajax request' FAILED
>> No RJS statement that replaces or inserts HTML content.
>>
>> Thank you!
>> Evgeny
>>
>> =====controller
>>  def create
>>    @comment.save
>>
>>    respond_to do |format|
>>          format.js
>>    end
>>  end
>>
>> =====create.rjs
>> comment_id = "comment_"+ at comment.id.to_s
>>
>> page['add_comment'].hide
>> page.insert_html :top, 'comments_list', :partial => "comments/
>> comment", :locals => {:comment => @comment, :item => @item}
>> page.visual_effect :highlight, comment_id, :duration => 1
>>
>> =====spec file
>>  it "renders a create.rjs template when comment is successfully
>> created in ajax request" do
>>    request.env["HTTP_ACCEPT"] = "application/javascript"
>>    post :create, :item_id => 1, :item_type => "Space", :comment =>
>> {:content => "text"}
>>
>>    response.should render_template("create")
>>    response.should have_rjs
>>  end
>
> Controller specs, by default, do not render templates. If you want to
> specify the contents of a template from your controller spec, tell it
> to integrate_views (hmmm - maybe we should change that to
> render_views???)
>
> describe MyController do
>  integrate_views
>  it "does something" do
>    ...
>  end
> end
>
> HTH,
> David

I'd say it's a matter of perspective. The name "integrate_views" is  
suitable from the perspective of the views being integrated into the  
execution stack. The name "renders_views" is suitable from the  
perspective of identifying that a controller example group renders its  
views.
-Nick


More information about the rspec-users mailing list