I am building a web application with Ruby on Rails 3.1 (RC1). I use Factory Girl, RSpec and Cucumber (with Capybara) for testing, but I experience an unexpected uplift ActionDispatch::ClosedErrorat some points (not every time) when I create new users (by creating the User model). The following is the error message:
Cannot modify cookies because it was closed. This means it was already streamed
back to the client or converted to HTTP headers. (ActionDispatch::ClosedError)
Error using these methods to create users:
- Creating with Factory Girl
Factory.create( :user )Factory.build( :user ).save
- Base creation
User.create( { ... } )User.new( { ... } ).save
It's funny that they work during some test, but not in others, and this does not seem random, although I can not understand the reason. Below is a snippet of 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 ]
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
assigns[ :user ].should == user
end
end
However, the error does not occur in the following code block:
"GET edit" do @user 'do get: edit, id: user.id # [: user].should == user
, , , .
, , !