我是 RSpec 的新手,正在尝试编写一个简单的测试来显示 Devise 正在工作。我选择了一个随机页面并想编写一个测试来显示未登录的用户被重新重定向到 /users/sign_in。
describe OrgsController do
describe "GET index when not logged in" do
it "redirects to new_user_session_path" do
user = FactoryGirl.create(:user)
user.confirm!
sign_in user
sign_out user
get :index
response.should redirect_to new_user_session_path
end
end
before(:each) do
user = FactoryGirl.create(:user)
user.confirm!
sign_in user
end
# remaining specs
end
我明白了"Expected response to be a redirect to <http://test.host/users/sign_in?locale=en> but was a redirect to <http://test.host/users/sign_in>."
我已经实现了 i18n,并且在我的应用程序控制器中有:
before_filter :set_i18n_locale_from_params
就以下方面而言,使其工作的最佳方法是什么:
- 让路线匹配?
- 再次签入和签出用户以绕过 before(:each) 块的影响的 hackishness?
- 整体做法?