When running bundle exec rspec on my sample rails app from the Michael Hartl tutorial I'm getting error `Argument Error: Factory not registered: user'
I have seen a bunch of extremely similar questions asked but I have tried the two solutions I have seen which are
a) Reboot the rails server b) Install 'factory_girl_rails"
Relevant sections of my Gemfile :
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.0'
gem 'bootstrap-sass', '2.3.2.0'
gem 'bcrypt-ruby', '3.0.1'
group :test do
gem 'selenium-webdriver', '2.0.0'
gem 'capybara', '2.1.0'
gem 'factory_girl_rails', '4.2.1'
end
Facotries.rb
#root/spec/factories.rb
FactoryGirl.define do
factory :user do
name "Michael Hartl"
email "[email protected]"
password "foobar"
password_confirmation "foobar"
end
end
user_pages_spec.rb
#root/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
describe "signup page" do
before { visit signup_path }
it { should have_content('Sign up') }
it { should have_title('Sign up') }
end
end
show.html.erb
#root/app/views/user/show.html.erb
<% provide(:title, @user.name) %>
<h1><%= @user.name %></h1>
Error output
Failures:
1) User pages profile page
Failure/Error: let(:user) { FactoryGirl.create(:user) }
ArgumentError:
Factory not registered: user
# ./spec/requests/user_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
# ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
I've never ceded to the stack overflow gods before but I'm about to toss my computer out of a window. Help is much appreciated!
Bigxiang's comment is the solution. I'm a beginner and actually didn't know that the names of my directories were important. A typo was causing the problem.