如何用会话变量测试redirect_to的rspec

时间:2011-10-22 11:29:06

标签: ruby-on-rails ruby-on-rails-3.1 rspec2

以下是update控制器的Customers操作中的一行代码。如何在RSpec中测试redirect_to

 redirect_to session[('page' + session[:page_step].to_s).to_sym], :notice => 'Customer was updated successfaully!'

有什么想法?感谢。

1 个答案:

答案 0 :(得分:4)

it "redirects to the next step" do
  # assign the current step
  session[:page_step] = "next"

  put :update
  response.should redirect_to("pagenext")
end

另请注意,您的代码中有拼写错误:successfaully。您可以将代码简化为

redirect_to session[:"page#{session[:page_step]}"], :notice => 'Customer was updated successfully!'