Ruby on rails 路由规范中的动态方法调用

Ruby on rails 路由规范中的动态方法调用,ruby-on-rails,dynamic,methods,rspec,Ruby On Rails,Dynamic,Methods,Rspec,我正在Rails 3.2应用程序中使用rspec测试路由的简单get请求。因为所有的都是get请求,并且都有不同的操作名称,这些名称与视图的名称类似,所以手动为每个get请求编写不同的测试是非常重复的 相反,我想提出这样的想法: %(action_1 action_2 action_3 action_4).each do |action| it "routes to the #{action} page" do get("liver_diseases#{action}_p

我正在Rails 3.2应用程序中使用rspec测试路由的简单get请求。因为所有的都是get请求,并且都有不同的操作名称,这些名称与视图的名称类似,所以手动为每个get请求编写不同的测试是非常重复的

相反,我想提出这样的想法:

%(action_1 action_2 action_3 action_4).each do |action|
    it "routes to the #{action} page" do
        get("liver_diseases#{action}_path").should route_to("liver_diseases##{action}")
    end
end
它在以下伪代码处失败:
get(“肝脏疾病”{action}\u路径”)
因此,我需要做的是一个动态方法调用——但我发现,这将涉及
.send(:method\u name)
,我需要知道它的类名。我找不到

要使此方法调用工作,我需要做什么

这将涉及.send(:method_name),我需要知道它的 类名

当接收器丢失时,它总是
self
。在控制器示例的上下文中,
self
应该是控制器实例。因此,您应该能够通过以下方式获得该路径:

send "liver_diseases_#{action}_path"
这应等同于:

controller.send "liver_diseases_#{action}_path"
这将涉及.send(:method_name),我需要知道它的 类名

当接收器丢失时,它总是
self
。在控制器示例的上下文中,
self
应该是控制器实例。因此,您应该能够通过以下方式获得该路径:

send "liver_diseases_#{action}_path"
这应等同于:

controller.send "liver_diseases_#{action}_path"

对于@Charles的特定需求:
get(发送(“hello#world#{action}}}路径”)。应该
等将起作用。对于@Charles的特定需求:
get(发送(“hello#world{action}路径”)。应该
等将起作用。