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
精彩评论