2014-05-19 49 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' }