ActionDispatch::测试Rails 3.1模型创建时的ClosedError(RSpec/Cucumber)
我正在用RubyonRails3.1(RC1)创建一个web应用程序。我正在使用Factory Girl、RSpec和Cucumber(与Capybara一起)进行测试,但在创建新用户(通过用户模型的创建操作)时,我遇到了意想不到的问题。下面是我收到的错误消息:ActionDispatch::测试Rails 3.1模型创建时的ClosedError(RSpec/Cucumber),cucumber,rspec2,factory-bot,ruby-on-rails-3.1,actiondispatch,Cucumber,Rspec2,Factory Bot,Ruby On Rails 3.1,Actiondispatch,我正在用RubyonRails3.1(RC1)创建一个web应用程序。我正在使用Factory Girl、RSpec和Cucumber(与Capybara一起)进行测试,但在创建新用户(通过用户模型的创建操作)时,我遇到了意想不到的问题。下面是我收到的错误消息: Cannot modify cookies because it was closed. This means it was already streamed back to the client or converted to HTT
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.build(:user).save
- 基本创作
User.create({…})
User.new({…}).save
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
但是,以下代码块中不会出现错误:
描述“获取编辑”操作
它“将请求的用户分配为@user”do
get:edit,id:user.id#这不会引发错误
分配[:用户]。应==用户
结束
结束
下面的任何其他方法都不会引发错误,即使我以完全相同的方式创建用户
任何关于我可能做错什么的建议都将不胜感激 这是由于rails 3现在处理响应的方式。他们在edge上发布了对flash中相同问题的修复,但还没有在Cookie中发布。现在我已经关闭了我的请求规格。如果没有人在这之前解决这个问题,我将在这个周末研究这个问题
有人在这里发布了一个解决方法
为了不必遵循链接,下面是我修改过的authlogic解决方案:
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.maintain_sessions = false if Rails.env == "test"
end
end
class用户
我没有在每个.save呼叫上确保会话管理,而是在测试时关闭它们。谢谢,这就解释了错误。我希望尽快修复cookies,以便我的规范能够正确运行。