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

Evgeny Bogdanov evgeny.bogdanov at gmail.com
Thu Feb 26 11:01:10 EST 2009


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


More information about the rspec-users mailing list