开发者

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/开发者_Python百科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?


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


'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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜