3
我正在運行rails 3.0.9和ruby 1.9.2以及從rails上的Hartl ruby教程開始工作。我也運行spork。使用factory_girl_rails訴1.1.0帶導軌3的工廠女孩給出錯誤消息:'驗證失敗:名稱不能爲空'
Failures:
1) UsersController GET 'show' should be successful
Failure/Error: @user = Factory(:user)
ActiveRecord::RecordInvalid:
Validation failed: Name can't be blank
# ./spec/controllers/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'
Finished in 0.38122 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/controllers/users_controller_spec.rb:12 # UsersController GET 'show' should be successful
先生factories.rb文件
Factory.define :user do |user|
user.name "Michael Hartl"
user.email "[email protected]"
user.password "foobar"
user.password_confirmation "foobar"
end
User_controller_spec.rb文件
require 'spec_helper'
describe UsersController do
render_views
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
# it "show the right user" do
# get :show, :id => @user
# assigns(:user).should == @user
# 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
show.html.rb文件
<%= @user.name %>, <%= @user.email %>
添加了factory_girl_rails 1.0回(我以前曾嘗試1.1.0,因爲1.0不會工作),而不刪除1.1.0,它現在工作。不知道我明白爲什麼,但... – WillLA