sin*_*enm 3 cucumber rspec2 actiondispatch ruby-on-rails-3.1 factory-bot
我正在使用Ruby on Rails 3.1(RC1)创建一个Web应用程序.我正在使用Factory Girl,RSpec和Cucumber(与Capybara)进行测试,但是ActionDispatch::ClosedError当我创建新用户时(通过User模型的创建操作),我在某些时候(不是每次)遇到意外的提升.以下是我收到的错误消息:
Cannot modify cookies because it was closed. This means it was already streamed
back to the client or converted to HTTP headers. (ActionDispatch::ClosedError)
Run Code Online (Sandbox Code Playgroud)
使用这些创建用户的方法时会引发错误:
Factory.create( :user )Factory.build( :user ).saveUser.create( { ... } )User.new( { ... } ).save有趣的是,他们在一些测试中工作,但在其他测试中没有,并且它看起来并不随机,尽管我无法弄清楚原因.以下是我的代码的摘录:
需要'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
Run Code Online (Sandbox Code Playgroud)
但是,以下代码块中不会引发错误:
描述'GET编辑'执行它'将所请求的用户指定为@user'do get:edit,id:user.id#这引发没有错误分配[:user] .should == user end end
下面的任何其他方法都不会引发错误,即使我以完全相同的方式创建用户.
任何关于我可能做错的建议都将不胜感激!
| 归档时间: |
|
| 查看次数: |
839 次 |
| 最近记录: |