我的 routes.rb 中有这个
scope constraints: lambda { |r| r.env['warden'].user.nil? } do
get "login", to: "sessions#new", as: "login"
end
我尝试通过 get "get 'signup'" 在 rspec 上访问这些,但它不起作用。
规格/控制器/sessions_controller_spec.rb
describe "/sessions/new" do
it "will render if user is not yet logged in" do
get :new
response.response_code.should eq 200
end
it "will not render if user is logged in" do
user = FactoryGirl.create(:user)
request.env['warden'].set_user(user)
get "login"
response.response_code.should eq 404
end
end
这是我得到的错误:
Failure/Error: get "login"
ActionController::RoutingError:
No route matches {:controller=>"sessions", :action=>"login"}