我正在用Ruby on Rails 3.1(RC1)创建一个Web应用程序。 我正在使用Factory Girl , RSpec和Cucumber (与Capybara )进行测试,但是当我创建新用户时(通过用户模型的创建操作),我遇到意外提出的ActionDispatch::ClosedError s某些时间(并非每次) 。 以下是我得到的错误消息:
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编辑'做它'将用户指定为@user'do get:edit,id:user.id#这会引发无错分配[:user] .should ==用户结束结束
在此之下的任何其他方法都不会引发错误,即使我以完全相同的方式创建用户。
任何建议,我可能做错了将不胜感激!
I am creating a web application with Ruby on Rails 3.1 (RC1). I am using Factory Girl, RSpec and Cucumber (with Capybara) for testing, but I am experiencing unexpected raised ActionDispatch::ClosedErrors some of the times (not every time) when I am creating new users (through the User model's create action). Below is the error message that I get:
Cannot modify cookies because it was closed. This means it was already streamed back to the client or converted to HTTP headers. (ActionDispatch::ClosedError)The error is raised when using these ways of creating users:
Creation using Factory Girl Factory.create( :user ) Factory.build( :user ).save Basic creation User.create( { ... } ) User.new( { ... } ).saveWhat is funny is that they do work during some test, but not in others, and it does not seem random, although I cannot figure out the reason. Below is an excerpt from my code:
users_controller_spec.rb
require '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 endHowever, the error is not raised in the following code block:
describe 'GET edit' do it 'assigns the requested user as @user' do get :edit, id: user.id # This raises no error assigns[ :user ].should == user end end
Any other method below this does not raise the error, even though I am creating users in the exact same way.
Any suggestions to what I might be doing wrong would be greatly appreciated!
最满意答案
这是由于rails 3现在响应的方式。 他们针对Flash中的相同问题发布了修复方案,但尚未在Cookie中发布。 现在我已经关闭了我的请求规格。 如果在此之前没有人接触到这个问题,我将在本周末看看这个问题。
https://github.com/rails/rails/issues/1452
This is due to the way rails 3 streams the response now. They posted a fix in edge for the same issue in flash but not in cookies yet. For now I have turned off my request specs. I am going to look at the problem this weekend if no one gets to it before then.
https://github.com/rails/rails/issues/1452
更多推荐
发布评论