考慮下面的集成測試:如何從Rails集成測試訪問會話?
test "if there is no user in session, redirect to index and flash message" do
open_session do |sess|
post '/login', :email => users(:client).email, :password => 'rumpelstiltskin'
sess[:user] = nil
get '/user_page'
assert_redirected_to index_path
assert_equal "Your session has expired. Please log in again", flash[:notice]
end
end
這會產生錯誤:
而且,更改爲sess.session[:user] = nil
產生一個錯誤,以及:NoMethodError: undefined method 'session' for nil:NilClass
如何從一個整合修改會話PARAMS在Rails中測試?
工作在Rails 3.0.7,Ruby 1.9.2p180,單元測試框架。
編輯:
get '/user_page', nil, {:user => nil}
和get ('/user_page', nil, {:user => nil})
生成錯誤。
這是單元測試還是集成測試? :) – Rimian