自定义路由访问Rspec

时间:2013-03-09 09:48:06

标签: ruby-on-rails rspec routes

我在我的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"}

1 个答案:

答案 0 :(得分:0)

spec / controllers / sessions_controller_spec.rb用于测试SessionsController。 signup是UsersController中的一个操作。测试spec / controllers / users_controller_spec.rb中的signup操作。