简体   繁体   English

如何使用rspec测试不同的路由,但是使用相同的控制器方法?

[英]How can I test with rspec different routes but to the same controller method?

I can explain. 我可以解释。

On my routes I have this: 在我的路线上我有这个:

resources :questions, :path => 'pq', only: [:index, :show, :create] do
  #many other routes...
  member do
    post :up_vote, action: :vote, vote: 1
    post :down_vote, action: :vote, vote: -1
  end
end

You can observe, it has two routes for the same action, but send a param 'vote' for both. 你可以观察到,它有两条相同动作的路线,但两者都发送一个参数'投票'。

I tried test with rspec using: 我尝试用rspec测试:

before{ post :up_vote, id: 1 }

Or 要么

before{ post :vote, id: 1, vote: 1 }

But I haven't no success, always returns No routes matches 但我没有成功,总是返回No routes matches

Anyone know how can I test with rspec it? 任何人都知道如何用rspec测试它?

删除resources行上的only条款并重新测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM