2014-05-19 50 views
0

现在我经历了一段时间,请求修改被控制器规格所忽略。Rspec请求修改被忽略

的spec_helper是,用于求出误差的目的,冷凝以

ENV["RAILS_ENV"] ||= 'test' 

require File.expand_path("../../config/environment", __FILE__) 
require 'rspec/rails' 
require 'rspec/autorun' 
require "webmock/rspec" 

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 

RSpec.configure do |config| 
    config.mock_with :rspec 
    config.infer_base_class_for_anonymous_controllers = false 
end 

控制器规范本身看起来像这样(忽略其它上下文)

require 'spec_helper' 
require 'rest-client' 

describe SessionsController, :type => :controller do 
    describe '#create' do 
    it 'should [something]' do 
     session[:return_point] = root_path 
     post :create, {:sessions => {:email => '[email protected]', :password => :123}} 
    end 
    end 
end 

和sessions_controller被冷凝到

class SessionsController < GuestBaseController 
    def create 
    raise session.inspect 
    end 
end 

这个规范内的结果是{},这显然是错误的,因为我只是把一些东西放入会话中。

问题部分: 我没有设置一些会话魔术/模拟和存根魔术的配置变量吗?

我与request.cookiesresponse.cookies有同样的问题。 我可以设置它们,但它们被忽略。

任何帮助将appriciated。

回答

0

在控制器的规格可以修改为request对象的一部分的会话或可以将它作为第二散列于请求消息:

request.session[:return_point] = root_path 
get :index, {}, { another_session: 'is merged with the request session' }