Zac Mackey
2013-Aug-02 01:20 UTC
Stack Overflow hasn''t been able to answer my Rspec question thus far.
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-error-undefined-method-downcase-for-nilnilclass
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-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org"
password "foobar"
password_confirmation "foobar"
endend
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/8d4d37d1-bd75-491b-8263-da5edcdd548d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.