我正在用Ruby on Rails 3.1(RC1)创建一个Web应用程序。我使用工厂女孩,RSpec的和黄瓜(与水豚)进行测试,但我遇到意外上调ActionDispatch::ClosedError
s的照片时(不是每个时间),当我创建新用户(通过的用户模型的创建操作)。下面是我得到的错误信息:当测试Rails 3.1模型创建(RSpec/Cucumber)时,ActionDispatch :: ClosedError
Cannot modify cookies because it was closed. This means it was already streamed
back to the client or converted to HTTP headers. (ActionDispatch::ClosedError)
的错误是创建用户的这些方式时提出:利用工厂女孩
Factory.create(:user)
Factory.build(:user).save
- 创作
- 基本创作
User.create({ ... })
User.new({ ... }).save
什么是有趣的是,他们的一些测试期间的工作,但不是别人,它似乎并没有随机的,虽然我不能找出原因。下面是从我的代码的摘录:
users_controller_spec.rb
需要 'spec_helper'
def user
@user ||= Factory.create(:user)
end
def valid_attributes
Factory.attributes_for :user
end
describe UsersController do
describe 'GET index' do
it 'assigns all users as @users' do
users = [ user ] # The call to user() raises the error here
get :index
assigns[ :users ].should == users
end
end
describe 'GET show' do
it 'assigns the requested user as @user' do
get :show, id: user.id # The call to user() raises the error here
assigns[ :user ].should == user
end
end
但是,错误并不在下面的代码块中引发:
描述'GET edit'do 它'将请求的用户分配为@user'do get:edit,id:user.id#这不会产生错误 分配[:user] .should ==用户 结束 结束
以下任何其他方法都不会引发错误,即使我以完全相同的方式创建用户。
对于我可能会做错的任何建议将不胜感激!
谢谢,这解释了错误。我希望尽快修复cookies,以便我的规格正确运行。 – sindrenm 2011-06-02 10:39:52