Forum: Ruby on Rails Stack Overflow hasn't been able to answer my Rspec question thus far.

465505a4e523752235ffb7d41b0c0694?d=identicon&s=25 Zac Mackey (Guest)
on 2013-08-02 14:00
(Received via mailing list)
I'm copying this directly from Stack Overflow to see if anyone can help.
Here is the link to my question on Stack Overflow:


<goog_622445784>

http://stackoverflow.com/questions/18006056/rspec-...


I keep getting this error when running my Rspec test and can't figure
out
why. I'm pretty new to Rails (and programming in general) so any
direction
or help would be much appreciated!

Failures:
1) User pages profile page
 Failure/Error: before { visit user_path(user) }
 ActionView::Template::Error:
   undefined method `downcase' for nil:NilClass
 # ./app/helpers/users_helper.rb:5:in `gravatar_for'
 # ./app/views/users/show.html.erb:3:in
`_app_views_users_show_html_erb__1766857043046396980_38603940'
 # ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top
(required)>'
2) User pages profile page
 Failure/Error: before { visit user_path(user) }
 ActionView::Template::Error:
   undefined method `downcase' for nil:NilClass
 # ./app/helpers/users_helper.rb:5:in `gravatar_for'
 # ./app/views/users/show.html.erb:3:in
`_app_views_users_show_html_erb__1766857043046396980_38603940'
 # ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top
(required)>'
Finished in 0.46129 seconds39 examples, 2 failures
Failed examples:

rspec ./spec/requests/user_pages_spec.rb:12 # User pages profile page
rspec ./spec/requests/user_pages_spec.rb:11 # User pages profile page

I'm in Chapter 7.13 of the Ruby on Rails tutorial. The tests cleared
just
fine until I added the Gravatar code and FactoryGirls Gem.

*/app/helpers/users_helper.rb file*

module UsersHelper

  # Returns the Gravatar (http://gravatar.com/) for the given user.
  def gravatar_for(user)
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
    image_tag(gravatar_url, alt: user.name, class: "gravatar")
  endend

*spec/requests/user_pages_spec.rb*

require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }
    before { visit user_path(user) }

    it { should have_content(user.name) }
    it { should have_title(user.name) }
  end...end


*And the last reference: app/views/users/show.html.erb*

<% provide(:title, @user.name) %><h1>
  <%= gravatar_for @user %>
  <%= @user.name %> </h1>


*Here is the factory file:*

FactoryGirl.define do
  factory :user do
    name     "Michael Hartl"
    email    "michael@example.com"
    password "foobar"
    password_confirmation "foobar"
  endend
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.