why rspect tests fail but the app works as expected?
===

I've been following the Rails Tutorial by Michael Hartl. Actually I already finished it, but I am having some problems with some refactoring I did for the last exercise of the final chapter. All I did was changing the show view for the user model (show.html.erb) from this:

    <section>
      <h1>
        <%= gravatar_for @user %>
        <%= @user.name %>
      </h1>
    </section>

To this:

    <section>      
	   <%= render 'shared/user_info' %>
    </section>

And in the partial(_user_info.html.erb) I have this:

    <a href="<%= user_path(current_user) %>">
       <%= gravatar_for current_user, size: 52 %> 
    </a> 
    <h1> <%= current_user.name %> </h1> 
    <% unless current_page?(user_path(current_user)) %>	
	   <span> <%= link_to "view my profile", current_user %> </span>
	   <span> <%= pluralize(current_user.microposts.count, "micropost") %> </span>
    <% end %>

Everything works fine on the browser, but for some reason rspec is failing some tests, I suspect rspec is having problems calling the current_user method which is defined in sessions_helper.rb, which by the way is included in application_helper.rb. The gravatar_for function is defined in users_helper.rb. Here is the error I get from the tests:

 Failure/Error: before { visit user_path(user) }
     ActionView::Template::Error:
       undefined method `email' for nil:NilClass
     # ./app/helpers/users_helper.rb:4:in `gravatar_for'
     # ./app/views/shared/_user_info.html.erb:1:in `_app_views_shared__user_info_html_erb___3480157814439046731_47327400'
     # ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb___1252254778347368838_47378900'
     # ./spec/requests/user_pages_spec.rb:58:in `block (3 levels) in <top (required)>'

I would appreciate if you could help me identify what is going on here. I could find different ways to do the same thing but I am just very curious about this. I am not very experienced in Rails which is why I followed the tutorial so forgive me if I am missing something obvious. Thanks.