Blankman
Blankman

Reputation: 266978

rspec title test is failing, I am setting the title?

My rspec title test is failing with:

1) HomeController Get 'index should have the right title
     Failure/Error: response.should have_selector("title",
     expected following output to contain a <title>TitleTest</title> tag:
     <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
     # ./spec/controllers/home_controller_spec.rb:13

My homecontroller has:

def index() @title = "TitleTest" end

my view (application.html.erb) has:

<title><%= @title %></title> 

Running rails server shows that my title does get set, what's wrong here?

Upvotes: 0

Views: 871

Answers (2)

Armando Flores
Armando Flores

Reputation: 11

'render_views' is definitely needed. I also ran into a similar situation and my problem was that I did not retrieve the page before executing the expectation. In other words, the structure should be:

describe... 

 it...  # previous expectation

 it...
   get 'mypage' 
   response should...

I was wrongly assuming that I did not need to get 'mypage' and that I could reuse the response from a previous expectation

Upvotes: 1

Anukul Veeraraghavan
Anukul Veeraraghavan

Reputation: 229

Make sure that in your controller spec, you have it set to render_views. Otherwise, rspec will not have the view to look into. Just add that bit of code right after your describe controller block.

Update: You can find an example right here

Upvotes: 2

Related Questions