2011-06-07 50 views
2

我想爲我的一個控制器編寫一個非常基本的功能測試,但問題是它不能識別我的任何路由。他們都通過HTTP在應用程序中工作,並可以在耙路中看到。不能識別任何路由的功能測試

事實上我甚至增加

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) 

耙路線:

   POST /users(.:format)      {:controller=>"users", :action=>"create"} 
new_user_en_gb GET /users/new(.:format)     {:controller=>"users", :action=>"new"} 
+0

什麼測試工具是你在用嗎?它對我來說沒有rspec-ish ...這只是因爲我從來沒有使用任何超出rspec的任何東西來進行我的單元測試(功能和其他) – jaydel 2011-06-07 13:20:43

+1

也是,完整的跟蹤是什麼?這可能是真正的錯誤被整個路由錯誤的東西掩蓋... – jaydel 2011-06-07 13:21:41

+2

它是[測試::單元](http://test-unit.rubyforge.org/),測試框架是標準的一部分Ruby庫(Ruby自帶)。 – danneu 2011-06-07 15:50:33

回答

3

嘗試增加了路由本身的功能測試,看看是否通過,並從那裏出發。

喜歡的東西:

test "should route to new user" do 
    assert_routing '/users/new', { :controller => "users", :action => "new" } 
end 
+0

謝謝,第一次使用路線中的區域設置。這是問題所在,我沒有通過現場,這個測試抓住了它! – 2011-06-08 09:49:58

+0

太棒了 - 很高興它的工作。 – jefflunt 2011-06-08 14:10:10

0

這是在我的 「征途」 創業板的問題。他們在旅程1.0.4中提出了更嚴格的路線,這些路線只在「測試」環境中出現。這對「發展」和「生產」有好處。

**確保您使用完全相同的參數,在路線聲明**

要麼添加:

get :index, :locale => "en" 

或在您的Gemfile更新:

gem 'journey', '1.0.3'