Reputation: 503
Hi I am currently at chapter 10 of michael hartl's tutorial and there is this small part of the tutorial which i cant seem to get through.
when i run bundle exec rspec spec/requests/micropost_pages_spec.rb
,it keeps failing.
Attached are the failures:
Failures:
1) Micropost pages micropost creation with invalid information should not create a micropost
Failure/Error: before { visit root_path }
ActionView::Template::Error:
wrong number of arguments (2 for 1)
# ./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__742172174590561382_70297875133320'
# ./app/views/static_pages/home.html.erb:5:in `_app_views_static_pages_home_html_erb___3080353205945370821_70297875083140'
# ./spec/requests/micropost_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
2) Micropost pages micropost creation with invalid information error messages
Failure/Error: before { visit root_path }
ActionView::Template::Error:
wrong number of arguments (2 for 1)
# ./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__742172174590561382_70297875133320'
# ./app/views/static_pages/home.html.erb:5:in `_app_views_static_pages_home_html_erb___3080353205945370821_70297875083140'
# ./spec/requests/micropost_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
3) Micropost pages micropost creation with valid information should create a micropost
Failure/Error: before { visit root_path }
ActionView::Template::Error:
wrong number of arguments (2 for 1)
# ./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__742172174590561382_70297875133320'
# ./app/views/static_pages/home.html.erb:5:in `_app_views_static_pages_home_html_erb___3080353205945370821_70297875083140'
# ./spec/requests/micropost_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
Attached is the app/helpers/users_helpers.rb:
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")
end
end
Attached is the _user_info.html.erb:
<%= link_to gravatar_for(current_user, size: 52), current_user %>
<h1>
<%= current_user.name %>
</h1>
<span>
<%= link_to "view my profile", current_user %>
</span>
<span>
<%= pluralize(current_user.microposts.count, "micropost") %>
</span>
Attached is the home.html.erb:
<% if signed_in? %>
<div class="row">
<aside class="span4">
<section>
<%= render 'shared/user_info' %>
</section>
<section>
<%= render 'shared/micropost_form' %>
</section>
</aside>
</div>
<% else %>
<div class="center hero-unit">
<h1>Welcome to the Sample App</h1>
<h2>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</h2>
<%= link_to "Sign up now!", signup_path,
class: "btn btn-large btn-primary" %>
</div>
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>
<% end %>
Attached is the micropost_pages_spec.rb:
require 'spec_helper'
describe "Micropost pages" do
subject { page }
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
describe "micropost creation" do
before { visit root_path }
describe "with invalid information" do
it "should not create a micropost" do
expect { click_button "Post" }.not_to change(Micropost, :count)
end
describe "error messages" do
before { click_button "Post" }
it { should have_content('error') }
end
end
describe "with valid information" do
before { fill_in 'micropost_content', with: "Lorem ipsum" }
it "should create a micropost" do
expect { click_button "Post" }.to change(Micropost, :count).by(1)
end
end
end
end
Upvotes: 0
Views: 437
Reputation: 47548
def gravatar_for(user)
...
The method signature specifies one argument. But in the view the method is called with two arguments:
link_to gravatar_for(current_user, size: 52)
Thus the error, wrong number of arguments (2 for 1)
You probably need to redefine the method signature, eg.:
def gravatar_for(user, options={})
Upvotes: 1