Seguo il tutorial di Michal Hartls Rails Capitolo 7. Ho installato la gemma Factory girl. Continuo a ricevere questo errore quando ho eseguito il mio testFabbrica non registrata: utente
Failures:
1) UsersController GET 'show' should be successful
Failure/Error: @user = FactoryGirl.create(:user)
ArgumentError:
Factory not registered: user
# ./spec/controllers/users_controller_spec.rb:10:in `block (3 levels) in <top (required)>'
Finished in 0.66336 seconds 42 examples, 1 failure
Failed examples:
rspec ./spec/controllers/users_controller_spec.rb:14 # UsersController GET 'show' should be successful
Gemfile
group :test do
gem 'autotest', '4.4.6'
gem "autotest-growl", "~> 0.2.16"
gem "autotest-rails", "~> 4.1.2"
gem "rspec", "~> 2.9.0"
gem 'rspec-rails', '2.9.0'
gem 'webrat', '0.7.3'
gem "spork", '0.9.0'
gem 'annotate', '~> 2.4.1.beta'
gem "factory_girl", "~> 3.2.0"
end
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platform =>
mio user_controller_spec.rb è
require 'spec_helper'
describe UsersController do
render_views
describe "GET 'show'" do
before(:each) do
@user = FactoryGirl.create(:user)
end
it "should be successful" do
get :show, :id => @user
response.should be_success
end
end
describe "GET 'new'" do
it "should be successful" do
get :new
response.should be_success
end
it "should have the right title" do
get :new
response.should have_selector('title', :content => "Sign up")
end
end
end
mio factories.rb è
FactoryGirl.create :user do |user|
user.name "Mark Brown"
user.email "[email protected]"
user.password "foobar"
user.password_confirmation "foobar"
end
I modificato
Factory(:name)
a
FactoryGirl.create(:user)
sulla linea 10 nella mia user_controller_spec.rb
becuase mi è stato sempre un avvertimento deprication. Pensavo che avrebbe risolto il problema, ma ora sto solo ricevendo.
Factory not registered: user
Qualcuno può dirmi cosa sta succedendo?
Questo ha funzionato per me. Grazie! –