测试轨功能时的错误

时间:2012-03-13 13:40:37

标签: ruby-on-rails testing

嗨,当我测试我的应用程序的功能部分时出现以下错误,基本上测试运行但我得到了这些错误,我不知道它指的是什么。

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'

推车控制器测试     要求&#39; test_helper&#39;

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

可能导致这种情况发生的原因是什么?

2 个答案:

答案 0 :(得分:1)

看起来加载灯具时遇到问题。它无法弄清楚如何解决carts定义中的setup方法。

您是否在test/fixtures/目录中进行了设置?

有关如何正确设置它们的信息,请参阅rails testing guide,但我猜你想要这样的事情:

test/fixtures/carts.yml

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

答案 1 :(得分:-1)

检查您是否已创建测试数据库。