2012-03-13 52 views
2

嗨,我測試我的應用程序的功能部分,基本上是測試運行,但我得到這些錯誤,我不知道它是指什麼時,我得到以下錯誤。錯誤,當測試鋼軌函數

AdminControllerTest: 
ERROR should get index (0.13s) 
NoMethodError: undefined method `users' for #<AdminControllerTest:0x007fe9e0119000>  /Users/@@@@@/Dropbox/blind/rack/ruby/1.9.1/gems/actionpack- 3.1.3/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing' 


CartsControllerTest: 
ERROR should create cart (0.12s) 
NoMethodError: undefined method `carts' for #<CartsControllerTest:0x007fe9de592b10> 
/Users/@@@@@/Dropbox/blind/rack/ruby/1.9.1/gems/actionpack 
3.1.3/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing' 

ERROR should destroy cart (0.17s) 
NoMethodError: undefined method `carts' for #<CartsControllerTest:0x007fe9de3569a0> 
/Users/@@@@@/Dropbox/blind/rack/ruby/1.9.1/gems/actionpack- 3.1.3/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing' 

ERROR should get edit (0.12s) 
NoMethodError: undefined method `carts' for #<CartsControllerTest:0x007fe9e10c19d0> 
/Users/@@@@@/Dropbox/blind/rack/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing' 

ERROR should get index (0.11s) 
NoMethodError: undefined method `carts' for #<CartsControllerTest:0x007fe9e10604f0> 
/Users/@@@@@/Dropbox/blind/rack/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing' 

ERROR should get new (0.11s) 
NoMethodError: undefined method `carts' for #<CartsControllerTest:0x007fe9e1033fe0> 
/Users/@@@@@/Dropbox/blind/rack/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing' 

ERROR should show cart (0.11s) 
NoMethodError: undefined method `carts' for #<CartsControllerTest:0x007fe9e10109c8> 
/Users/@@@@@/Dropbox/blind/rack/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing' 

ERROR should update cart (0.12s) 
NoMethodError: undefined method `carts' for #<CartsControllerTest:0x007fe9de460558> 
/Users/@@@@@/Dropbox/blind/rack/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing' 

車控制器測試 需要 'test_helper'

class CartsControllerTest < ActionController::TestCase 
setup do 
@cart = carts(:one) 
end 

test "should get index" do 
get :index 
assert_response :success 
assert_not_nil assigns(:carts) 
end 

test "should get new" do 
get :new 
assert_response :success 
end 

test "should create cart" do 
assert_difference('Cart.count') do 
post :create, cart: @cart.attributes 
end 

assert_redirected_to cart_path(assigns(:cart)) 
end 

test "should show cart" do 
get :show, id: @cart 
assert_response :success 
end 

test "should get edit" do 
get :edit, id: @cart 
assert_response :success 
end 

什麼可能會造成這種情況發生?

+0

發表您的管理員或推車控制器測試。 – James 2012-03-13 15:23:15

回答

-1

檢查您是否創建了測試數據庫。

+0

我不確定你的意思? – 2012-03-13 13:59:21

+0

我已經設置了固定裝置ymls,但當我嘗試測試時仍然出現同樣的錯誤。 – 2012-03-15 21:13:23

+0

這個答案措辭不妙。你的意思是「檢查你創建了測試數據庫」嗎? – 2012-04-03 10:14:15

1

看起來像加載燈具時出現問題。它無法弄清楚如何解決setup定義中的carts方法。

你把它們設置在你的test/fixtures/目錄中嗎?

rails testing guide關於如何正確設置這些信息,但我猜你想是這樣的:

test/fixtures/carts.yml

one: 
    name: bork 
    foo_attribute: bar_value 
two: 
    name: other_cart 
    foo_attribute: blah_value 
+0

我現在將看看我的裝置並回復您 – 2012-03-13 16:49:30