rspec中的ActionController :: UrlGenerationError

在测试控制器动作时,出现此路由错误。我无法弄清楚我做错了什么地方

路线

 get ':user_type',to: 'user_posts#index',param: :user_type,constraints: lambda { |req| ['abc','def'].include?(req.params["user_type"]) },as: :custom_posts


规格:

  describe "GET #index: enabled" do
    it "returns http success" do
      get :index,params: {user_type: 'abc'}
      expect(response).to have_http_status(:success)
    end
  end

错误:

actionController::UrlGenerationError:
       No route matches {:action=>"index",:controller=>"user_posts"}

此外,我通过更改路线在github上尝试了一种解决方案,但这对我不起作用

get ':user_type',constraints: {user_type: lambda { |req| ['abc','def'].include?(req.params["user_type"]) } },as: :custom_posts
tjb1216 回答:rspec中的ActionController :: UrlGenerationError

最后,我得到了答案。这是详细信息discussion

describe "GET #index: enabled" do
    it "returns http success" do
      get :index,params: { user_type: 'abc',param: :user_type }     
      expect(response).to have_http_status(:success)
    end
  end
本文链接:https://www.f2er.com/3009610.html

大家都在问