Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 514
user1040363 Avatar asked Jun 06 '12 05:06

user1040363


3 Answers

response.body.should == "OK"

works for me

like image 158
eagor Avatar answered Nov 19 '22 11:11

eagor


If you are using rails 3 or above

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

will work

like image 42
Balaji Radhakrishnan Avatar answered Nov 19 '22 10:11

Balaji Radhakrishnan


describe "render text OK" do   
  post :create, {:agent => valid_attributes}
  # response.should have_content("OK"
  response.should render_template(:text => "OK")
end
like image 1
Alexander Avatar answered Nov 19 '22 11:11

Alexander