Rspec rendering text

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 will try to check with rspec the renderer "OK"

This is my actual specification:

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

but this specification always answers 0 errors, even when I put "OKI" in the place of "OK"

Who has one suggestion for this?

+7
source share
3 answers

If you use rails 3 or higher

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

will work

+3
source
 response.body.should == "OK" 

works for me

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

All Articles