Why is ActionMailer::Base.deliveries.last.to undefined method nil? - ruby-on-rails

Given the following:
it "sends an email to user" do
subscription = FactoryGirl.create(:subscription, stripe_customer_token: 'bloop')
subscription.expire!
ActionMailer::Base.deliveries.last.to.should == [subscription.user.email]
end
I get:
Failure/Error: ActionMailer::Base.deliveries.last.to.should == [subscription.user.email]
NoMethodError: undefined method `to' for nil:NilClass
# ./spec/models/subscription_spec.rb:113:in `block (3 levels) in <top (required)>'
Which I don't understand, because if I do the same thing in development in console I'll see the email being sent. I have in test.rb config.action_mailer.delivery_method = :test
What could the issue be?

Related

RSpec respond_to does not work

This is my code snippet to test the polymorphic relationship.
I wrote test as below.
require 'rails_helper'
RSpec.describe Proration, type: :model do
let(:invoice_item) { FactoryGirl.create(:proration_invoice_item) }
subject { :invoice_item }
it { should be_valid }
it { should respond_to(:total_amount) }
it { should respond_to(:invoice) }
it { should respond_to(:itemable) }
end
But this errors out
Failures:
1) Proration should be valid
Failure/Error: it { should be_valid }
NoMethodError:
undefined method `valid?' for :invoice_item:Symbol
# ./spec/models/proration_spec.rb:7:in `block (2 levels) in <top (required)>'
2) Proration Proration should respond to #total_amount
Failure/Error: end
expected :invoice_item to respond to :total_amount
# ./spec/models/proration_spec.rb:16:in `block (3 levels) in <top (required)>'
3) Proration Proration should respond to #invoice
Failure/Error: end
expected :invoice_item to respond to :invoice
# ./spec/models/proration_spec.rb:17:in `block (3 levels) in <top (required)>'
4) Proration Proration should respond to #itemable
Failure/Error: Unable to find matching line in /Users/toshikiinami/Desktop/billing/spec/models/proration_spec.rb
expected :invoice_item to respond to :itemable
# ./spec/models/proration_spec.rb:18:in `block (3 levels) in <top (required)>'
Any ideas to fix this?
(respond_to for model doesn't work.)
You defined an invoice_item using let, but as a subject you're using symbol. What you want instead is that object invoice_item, so
subject{ :invoice_item }
should be changed to
subject{ invoice_item }

Rake db:seed NoMethodError: undefined method `sample'

I am trying to seed my database, but I am running into this error, and as a beginner do not know how to fix it. I'm trying to take a sample of bookmarks and assign them to some of my users. Any ideas why this is throwing an error? Here is the error:
vagrant#rails-dev-box:~/code/bookmarks$ rake db:seed
rake aborted!
NoMethodError: undefined method `sample' for #<Class:0xaa90cf4>
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.5/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/home/vagrant/code/bookmarks/db/seeds.rb:47:in `block (2 levels) in <top (required)>'
/home/vagrant/code/bookmarks/db/seeds.rb:46:in `times'
/home/vagrant/code/bookmarks/db/seeds.rb:46:in `block in <top (required)>'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.5/lib/active_record/relation/delegation.rb:13:in `each'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.5/lib/active_record/relation/delegation.rb:13:in `each'
/home/vagrant/code/bookmarks/db/seeds.rb:45:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `block in load'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.5/lib/rails/engine.rb:540:in `load_seed'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.5/lib/active_record/tasks/database_tasks.rb:154:in `load_seed'
/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.5/lib/active_record/railties/databases.rake:181:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
Edit: Here is my seeds.rb file:
require 'faker'
# Create a User
# user = User.new(
# name: 'First Last',
# email: 'firstlast#gmail.com',
# password: 'password',
# )
# user.skip_confirmation!
# user.save
#Create Users
5.times do
user = User.new(
name: Faker::Name.name,
email: Faker::Internet.email,
password: Faker::Lorem.characters(10)
)
user.skip_confirmation!
user.save!
end
users = User.all
#Create Bookmarks
10.times do
Bookmark.create!(
url: Faker::Internet.url
)
end
bookmarks = Bookmark.all
#Create Topics
10.times do
Topic.create!(
name: Faker::Lorem.sentence
)
end
topics = Topic.all
users.each do |user|
3.times do
user.bookmarks << Bookmark.sample
end
end
topics.each do |topic|
3.times do
user.topics << Topic.sample
end
end
puts "Seed finished"
puts "#{User.count} users created"
puts "#{Bookmark.count} bookmarks created"
puts "#{Topic.count} topics created"
Thanks in advance for your help!
whereever you are calling .sample, the object before it is apparently not the correct type of object. It should either be an array or the 'collection' which results when you query your database. Like this...
posts = Post.all
posts.sample would work correctly
any object which is not an array (or like an array) will not have the 'sample' method available for you to use
You cannot call sample on a class as that is not a valid method. The sample method is used for arrays or ActiveRecord::Relation arrays.
For example, each of these would return a random
[0,1,2,3].sample
(0..10).to_a.sample
Post.all.sample
However, something like these examples would give an error.
User.sample
NoMethodError: undefined method 'sample' for #<Class:0x00000007faa378>
(9..199).sample
NoMethodError: undefined method 'sample' for 9..199:Range

RSPEC failed with email formats

I have been browsing the Rails tutorial with putting together the user account and running tests on it for the project I am working on.
Failures:
1) when email format is invalid should be invalid
Failure/Error: #user.email = invalid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:71:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:70:in `each'
# ./spec/models/user_spec.rb:70:in `block (2 levels) in <top (required)>'
2) when email format is valid should be valid
Failure/Error: #user.email = valid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:80:in `each'
# ./spec/models/user_spec.rb:80:in `block (2 levels) in <top (required)>'
Finished in 0.527 seconds
9 examples, 2 failures
Failed examples:
rspec ./spec/models/user_spec.rb:67 # when email format is invalid should be invalid
rspec ./spec/models/user_spec.rb:78 # when email format is valid should be valid
I have no clue what the problem is. I see what it says, but I even C&P the code from the tutorial to double check what I did to ensure everything was type properly.
Here's the user_spec file.
https://gist.github.com/pwz2k/4770845
Here's the user.rb file.
https://gist.github.com/pwz2k/4770854
The fails did not appear until I added the email validation.
Make sure that you're creating #user before you start testing it.. do you have these lines in your User test? (rails tutorial listing 6.16)
before do
#user = User.new(name: "Example User", email: "user#example.com")
end
The error is very clear!. You're setting email to nil class. Which means you're supposed to set the email to a user which we say
#user.email = "something"
The error is complaining there is no user, and there won't be any email for user.
To make is work here is an example code which will help you to fix this issue.
describe "validations" do
before(:each) do
#user = User.new(name: "gates", email: "somename#gmail.com")
end
it "should be invalid" do
invalid_emails = %w{gs#gmail p.com name.gmail.com foo.ymail}
invalid_emails.each do |invalid_email|
#user.email = invalid_email
expect(#user.email).to_not be_valid
end
end
it "should be valid" do
#user.name = "somename"
valid_emails = %w{user#foo.COM A_US-ER#f.b.org frst.lst#foo.jp
a+b#baz.cn}
valid_emails.each do |valid_email|
#user.email = valid_email
expect(#user.email).to be_valid
end
end
end
Please be make sure you've created a fixure for user in your fixures folder.
Hope this helps!

Ruby tutorial chapter 8 - errors

Had three engineers working on trying to solve this and no luck. Working through Ruby on rails tutorial - Michael Hartl, Chapter 8 and can not seem to progress. If you are a jedi engineer please write answers in full due to rookie experience/knowledge. Thanks in advance!
errors
Failures:
1) when email format is invalid should be invalid
Failure/Error: #user.email = invalid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:33:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:32:in `each'
# ./spec/models/user_spec.rb:32:in `block (2 levels) in <top (required)>'
2) when email format is valid should be valid
Failure/Error: #user.email = valid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:43:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:42:in `each'
# ./spec/models/user_spec.rb:42:in `block (2 levels) in <top (required)>'
3) when email address is already taken
Failure/Error: user_with_same_email = #user.dup
TypeError:
can't dup NilClass
# ./spec/models/user_spec.rb:51:in `dup'
# ./spec/models/user_spec.rb:51:in `block (2 levels) in <top (required)>'
4) when password is not present
Failure/Error: before { #user.password = #user.password_confirmation = " " }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:60:in `block (2 levels) in <top (required)>'
5) when password doesn't match confirmation
Failure/Error: before { #user.password_confirmation = "mismatch" }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:65:in `block (2 levels) in <top (required)>'
6) when password confirmation is nil
Failure/Error: before { #user.password_confirmation = nil }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:70:in `block (2 levels) in <top (required)>'
7) with a password that's too short
Failure/Error: before { #user.password = #user.password_confirmation = "a" * 5 }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:76:in `block (2 levels) in <top (required)>'
8) return value of authenticate method with valid password
Failure/Error: before { #user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
9) return value of authenticate method with invalid password
Failure/Error: before { #user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
10) return value of authenticate method with invalid password
Failure/Error: before { #user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
11) Authentication signin page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841ca913c8>:0x007f8419313cc0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
12) Authentication signin page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841ca913c8>:0x007f841bba0030>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
13) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f8419475898>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
14) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f84195c97f8>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
15) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f84196d96e8>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
16) Static pages Help page
Failure/Error: before { visit help_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f84196268b8>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
17) Static pages Help page
Failure/Error: before { visit help_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841bd4b4e8>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
18) Static pages About page
Failure/Error: before { visit about_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841bbab728>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'
19) Static pages About page
Failure/Error: before { visit about_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841a1f8c18>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'
20) Static pages Contact page
Failure/Error: before { visit contact_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841b8baf00>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:30:in `block (3 levels) in <top (required)>'
21) Static pages Contact page
Failure/Error: before { visit contact_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841be450b0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:30:in `block (3 levels) in <top (required)>'
22) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bedc2d0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
23) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841b8890e0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
24) User pages signup with invalid information should not create a user
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bfd8940>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
25) User pages signup with valid information should create a user
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bd018c0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
Finished in 0.60263 seconds
33 examples, 25 failures
user_spec.rb
require 'spec_helper'
describe User do
before do
#user = User.new(name: "Example User", email: "user#example.com",
password: "foobar", password_confirmation: "foobar")
end
subject { #user }
it { should respond_to(:name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:authenticate) }
it { should be_valid }
describe "when name is too long" do
before { #user.name = "a" * 51 }
it { should_not be_valid }
end
end
describe "when email format is invalid" do
it "should be invalid" do
addresses = %w[user#foo,com user_at_foo.org example.user#foo.
foo#bar_baz.com foo#bar+baz.com]
addresses.each do |invalid_address|
#user.email = invalid_address
#user.should_not be_valid
end
end
end
describe "when email format is valid" do
it "should be valid" do
addresses = %w[user#foo.COM A_US-ER#f.b.org frst.lst#foo.jp a+b#baz.cn]
addresses.each do |valid_address|
#user.email = valid_address
#user.should be_valid
end
end
end
describe "when email address is already taken" do
before do
user_with_same_email = #user.dup
user_with_same_email.email = #user.email.upcase
user_with_same_email.save
end
it { should_not be_valid }
end
describe "when password is not present" do
before { #user.password = #user.password_confirmation = " " }
it { should_not be_valid }
end
describe "when password doesn't match confirmation" do
before { #user.password_confirmation = "mismatch" }
it { should_not be_valid }
end
describe "when password confirmation is nil" do
before { #user.password_confirmation = nil }
it { should_not be_valid }
end
describe "with a password that's too short" do
before { #user.password = #user.password_confirmation = "a" * 5 }
it { should be_invalid }
end
describe "return value of authenticate method" do
before { #user.save }
let(:found_user) { User.find_by_email(#user.email) }
describe "with valid password" do
it { should == found_user.authenticate(#user.password) }
end
describe "with invalid password" do
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
it { should_not == user_for_invalid_password }
specify { user_for_invalid_password.should be_false }
end
end
authentication_pages_spec
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
end
static_pages_spec
require 'spec_helper'
describe "Static pages" do
subject { page }
describe "Home page" do
before { visit root_path }
it { should have_selector('h1', text: 'Sample App') }
it { should have_selector('title', text: full_title('')) }
it { should_not have_selector 'title', text: '| Home' }
end
describe "Help page" do
before { visit help_path }
it { should have_selector('h1', text: 'Help') }
it { should have_selector('title', text: full_title('Help')) }
end
describe "About page" do
before { visit about_path }
it { should have_selector('h1', text: 'About') }
it { should have_selector('title', text: full_title('About Us')) }
end
describe "Contact page" do
before { visit contact_path }
it { should have_selector('h1', text: 'Contact') }
it { should have_selector('title', text: full_title('Contact')) }
end
end
user_pages_spec
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_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user#example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'bootstrap-sass', '2.0.0'
gem 'bcrypt-ruby', '3.0.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.10.0'
end
gem 'annotate', '~> 2.4.1.beta', group: :development
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '1.4.0'
end
group :production do
gem 'pg', '0.12.2'
end
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
Thanks in advance guys :)
It looks like you forgot to prepare the test database. Run this on the command line:
rake db:test:prepare
I would definitely recommend that you read A Guide to Testing Rails Applications (3.1 Preparing your Application for Testing) to get a sense of what needs to happen before you run your tests.

Rails Tutorial unexpected Failure/Error: get :show, :id => #user

I'm currently going through the awesome Rails Tutorial, and after I did a git reset to return to a previous commit, something broke to my database and all of a sudden I get 5 failures when I run rspec.
Failures:
1) UsersController Get 'show' should be successfull
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xaad9990>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
2) UsersController Get 'show' should find the right user
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xa820ca8>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:18:in `block (3 levels) in <top (required)>'
3) UsersController Get 'show' should have the right title
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0x9f0e7b4>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:23:in `block (3 levels) in <top (required)>'
4) UsersController Get 'show' should include the user's name
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb930cc8>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:28:in `block (3 levels) in <top (required)>'
5) UsersController Get 'show' should have a profile image
Failure/Error: get :show, :id => #user
ActionView::Template::Error:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb9ade94>
# ./app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb__463664834_89565070__435144589'
# ./spec/controllers/users_controller_spec.rb:33:in `block (3 levels) in <top (required)>'
I'm sure this easy to fix, but I honestly dont know where to even look at. Can anyone help?
This is your problem:
undefined method `gravatar_for' for #<#<Class:0xaadc884>:0xb9ade94>
You need to make sure the gravatar is specificed in your profile model.
You are calling gravatar_for, which is unknown, line 5 of: ./app/views/users/show.html.erb
Even if this is already an answer, please provide details so that we fix it.
I'm pretty sure you forgot to add the method to your User model.

Resources