3
레일즈 루비 레일즈 튜토리얼에서 레일즈 3.0.9와 루비 1.9.2를 실행 중입니다. 나는 또한 spork를 운영하고있다. 사용 factory_girl_rails V. 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 %>
1.1.0을 제거하지 않고 factory_girl_rails 1.0 back (이전에 1.1.0을 시도했으나 1.0이 작동하지 않았 음)을 추가했는데 이제 작동합니다. 이유는 모르겠지만 ... – WillLA