我正在运行rails 3.0.9和ruby 1.9.2并使用Hartl ruby on rails教程。我也在跑spork。使用factory_girl_rails v.1.1.0
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
Mr. factories.rb文件
Factory.define :user do |user|
user.name "Michael Hartl"
user.email "mhartl@example.com"
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 %>
答案 0 :(得分:1)
只是一个想法,但你重启Spork服务器了吗?这有时是必要的,有关详细信息,请参阅Spork: how to refresh validations and other code?。