开发者

Rspec2 Rails 3 Test view without including layout?

开发者 https://www.devze.com 2023-03-27 23:33 出处:网络
I\'ve been trying to test a number of views in my Rails 3 app, but I am getting hung up on the fact that the site\'s layout calls on AuthLogic\'s current_user, which I can never seem to set correctly

I've been trying to test a number of views in my Rails 3 app, but I am getting hung up on the fact that the site's layout calls on AuthLogic's current_user, which I can never seem to set correctly (I've been all over the web looking for that one, but no joy so far).

Then I realized that even when I figure out how to do that right, it's not very DRY to test the current user in every view, when it's only called in th开发者_运维问答e layout, so I'm now curious: Is there a way to test just the view (e.g. /app/views/my_model/show.html.erb) without having the layout applied to it?

I realize I'll still need integration tests later, but I wanted to isolate the view specs first if at all possible.


RSpec has support to spec the view templates (read more here: https://www.relishapp.com/rspec/rspec-rails/docs/view-specs/view-spec).

From my experience these specs do not render the layout, can test partials independently and are my preferred way of testing the generated HTML.

PS: you should also install the webrat gem to make your life easier

0

精彩评论

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