Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rspec 不知道为什么我';我在Rails中得到了这个路由错误;控制器规格是否使用routes.rb或仅使用字符串/符号来表示方法?_Rspec_Ruby On Rails 3.2 - Fatal编程技术网

Rspec 不知道为什么我';我在Rails中得到了这个路由错误;控制器规格是否使用routes.rb或仅使用字符串/符号来表示方法?

Rspec 不知道为什么我';我在Rails中得到了这个路由错误;控制器规格是否使用routes.rb或仅使用字符串/符号来表示方法?,rspec,ruby-on-rails-3.2,Rspec,Ruby On Rails 3.2,编辑#2 我正在为api编写一个快速测试套件,并且正在使用控制器规范。我正在尝试使用post/get调用的路由,但这些路由是否已被查询,或者它是否只是Controlmer方法的符号/字符串 原始问题 这可能是一个非常幼稚的问题,但我在rails中有一个命名的路由,并且正在用rspec进行测试。在routes.rb中,我有: match '/api/get-next-highest-position-in-menu-header' => 'api_edit#get_next_highest

编辑#2

我正在为api编写一个快速测试套件,并且正在使用控制器规范。我正在尝试使用post/get调用的路由,但这些路由是否已被查询,或者它是否只是Controlmer方法的符号/字符串


原始问题

这可能是一个非常幼稚的问题,但我在rails中有一个命名的路由,并且正在用rspec进行测试。在routes.rb中,我有:

match '/api/get-next-highest-position-in-menu-header' => 'api_edit#get_next_highest_position_in_menu_header', :as => :jt_next_highest
在我的规范中,我有以下内容:

post :jt_next_highest,  { menu_header_id: mh.id }
但是我得到了以下错误

1) ApiEditController Adding a Item should get the next highest position in a menu_header
 Failure/Error: post :jt_next_highest,  { menu_header_id: mh.id }
 AbstractController::ActionNotFound:
   The action 'jt_next_highest' could not be found for ApiEditController
 # ./spec/controllers/api_edit_controller_spec.rb:52:in `block (3 levels) in <top (required)>'
我不确定这有什么问题,因为我觉得这应该行得通。你知道我做错了什么吗

编辑1

尝试:

post :jt_next_highest_path,  { menu_header_id: mh.id }
刚抓住我

   The action 'jt_next_highest_path' could not be found for ApiEditController

控制器规格完全绕过路由,所以

post :foo

在控制器规范中,
:foo
必须是操作名称,即控制器中方法的名称。映射到哪个路由并不重要(只要至少有一个路由)。

现在我只得到一个错误:
无法为ApiEditController找到操作“jt\u next\u highest\u path”
。我知道我在做一些愚蠢的事情,现在一切都有意义了。我使用这些规范来测试json api。这是合适的还是你觉得有更好的方法?很抱歉提出新问题,但我非常感谢您的建议。我选择使用控制器规范,因为这是用来测试他们的api的。
post :foo