Rspec rendering text

[亡魂溺海] 提交于 2019-12-22 03:57:42

问题


I have this Code

if @temp_user.save
  sign_in(:user, @temp_user)
  render text: "OK"
else
  render text: render_to_string(:partial => "errors")
end

and I try verify with rspec the render "OK"

this is my actual spec:

  it "render text OK" do   
    post :create, {:agent => valid_attributes}
    # response.should have_content("OK")
    response.should render_template(:text => "OK")
  end

but this spec respond 0 failures always, even when I put "OKI" in place "OK"

anyone have one suggestion for that?


回答1:


If you are using rails 3 or above

expect(response.body).to eq "OK"

will work




回答2:


response.body.should == "OK"

works for me




回答3:


describe "render text OK" do   
  post :create, {:agent => valid_attributes}
  # response.should have_content("OK"
  response.should render_template(:text => "OK")
end


来源:https://stackoverflow.com/questions/10908547/rspec-rendering-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!