views:

64

answers:

3

Hi,

I am following the railstutorial.org tutorial. While I am able to see the gravatar on the webpage, my rspec test is failing.

Here is the user_controller_spec.rb test:

describe "GET 'show'" do

  before(:each) do
    @user = Factory(:user)
  end

  it "should be successful" do
    get :show, :id => @user
    response.should be_success
  end

end

Here is the relevant show.html.erb file:

<table class="profile" summary="Profile information">
  <tr>
    <td class="main">
      <h1>
        <%= gravatar_image_tag(@user.email) %>
        <%= @user.name %>
      </h1>
    </td>
    <td class="sidebar round">
      <strong>Name</strong> <%= @user.name %><br />
      <strong>URL</strong> <%= link_to user_path(@user), @user %>
    </td>
  </tr>
</table>

I get an error stating "undefined method 'gravatar_image_tag'. I already installed the corresponding gem by executing "gem install gravatar_image_tag", added it to my gemfile, and also executed "bundle install". It is listed as installed when I execute "gem list"

I have been trying to debug this for several hours now. Any help would be appreciated. Thanks in advance. BTW, I'm running 32-bit Windows 7 with GIT Bash, RubyInstaller-1.9.2-p0.

Error message:

alt text

+1  A: 

Is the gravatar_image_tag gem global to all environments in your gemfile? If you have it in a group :development, :production block, or something similar, it wouldn't be available in test.

And I haven't tried it, but your line:

get :show, :id => @user

seems like it needs to be:

get :show, :id => @user.id

Jaime Bellmyer
Thanks man!!! That was the issue. I had the gravatar_image_tag gem in the development group!!! Thanks a lot!!!
szielenski
Glad I could be of help. Could you accept my answer, so I officially get credit? Thanks!
Jaime Bellmyer
+1  A: 

Hey szielenski

I'm the author of the gem. Can you open an issue on the github page http://github.com/mdeering/gravatar_image_tag/issues with the version of rails and a gem list for me. I will see if I can resolve the issue for you and post an answer back here.

I have some pre-release versions of the gem that I could push out to gemcutter that might resolve the issue already.

Cheers, Mike D.

Michael Deering
+1  A: 

Following the same tutorial, I had the same undefined method 'gravatar_image_tag' error, but a different solution from the accepted one above (my gem was in the correct place in the Gemfile, so that wasn't the problem).

Just had to restart the server (Ctrl C then rails server), and then everything was fixed.

T.J. Schuck