when i want to test an ajax action, it always can''t passed. The action code is: # POST /posts/:id/comments def create @comment = @post.comments.build(params[:comment]) if @comment.save flash[:notice] = ''Comment was successfully created.'' render :update do |page| page.insert_html :bottom, ''comments'', :partial => ''posts/comment'', :object => @comment page.replace_html ''comment'', :partial => ''comment'', :object => Comment.new end else render :update do |page| page.replace_html ''comment'', :partial => ''comment'', :object => @comment end end end and the test code is: describe "handling POST /posts/:id/comments" do before(:each) do @post = Post.new @comment = Comment.new Post.stubs(:find).returns(@post) @post.comments.stubs(:build).returns(@comment) end it "with successful save" do @comment.expects(:save).returns(true) xhr :post, :create, :post_id => @post.id, :comment => {} response.should have_rjs(:insert_html, :bottom, ''comments'') response.should have_rjs(:replace_html, ''comment'') end it "with failed save" do @comment.expects(:save).returns(false) xhr :post, :create, :post_id => @post.id, :comment => {} response.should have_rjs(:replace_html, ''comment'') end end The result is: 1) ''CommentsController handling DELETE /comments/:id with successful destroy'' FAILED No RJS statement that removes ''comment_'' was rendered. ./spec/controllers/comments_controller_spec.rb:38: 2) ''CommentsController handling POST /posts/:id/comments with successful save'' FAILED bottom. ./spec/controllers/comments_controller_spec.rb:16: But I can do it successfully by browser. So I think there''s something wrong with my rspec codes. Can anyone help me? Thanks in advanced. Best Regard, Richard -- My home: http://www.huangzhimin.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---