我正在尝试为我的一个 Controller 编写一个非常基本的功能测试,但问题是它无法识别我的任何路线。它们都通过 HTTP 在应用程序中工作,并且可以在 rake 路由中看到。
事实上我什至添加了
puts ActionController::Routing::Routes.inspect
它列出了我在发生错误之前的所有路线。
这是测试:
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
test "should get signup" do
get :new
assert_response :success
assert_not_nil assigns(:users)
end
end
错误:
1) Error:
test_should_get_signup(UsersControllerTest):
ActionController::RoutingError: No route matches {:controller=>"users", :action=>"new"}
/test/functional/users_controller_test.rb:5:in `test_should_get_signup'
1 tests, 0 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/Users/projectzebra/.rvm/rubies/ruby-1.8.7...]
(See full trace by running task with --trace)
rake 路线:
POST /users(.:format) {:controller=>"users", :action=>"create"}
new_user_en_gb GET /users/new(.:format) {:controller=>"users", :action=>"new"}
最佳答案
尝试为路由本身添加功能测试,看看是否通过,然后从那里开始。
类似于:
test "should route to new user" do
assert_routing '/users/new', { :controller => "users", :action => "new" }
end
关于ruby-on-rails - 功能测试无法识别任何路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6265471/