我正在尝试解决我在测试数据库中遇到的问题。我目前正在跟随敏捷Web开发4并完成各章。在我发现我的测试数据库持久存储数据的三分之三的某个地方,我目前正在试图找出究竟发生了什么。我有一个我试图运行的orders_controller_test.rb文件。
执行时
rake test:controllers
rake test test/controllers/orders_controller_test.rb
rake test
执行测试并保持数据。我想一次测试一个并执行此命令:
rake test test/controllers/orders_controller_test.rb name_of_test
如Rails 4指南中所示。执行此命令会产生以下结果:
正如您所看到的,它执行测试但实际上并没有这样做。没有断言,这让我感到困惑/沮丧。我已经参考过这篇网络文章,并尝试了其中的方法。 Different ways to run rails tests
为什么这不能正确执行。这非常令人沮丧,我怀疑这很简单。有人可以帮助确定可能发生的事情吗?非常感谢帮助。
----- EDIT -----------
控制器测试
require 'test_helper'
class OrdersControllerTest < ActionController::TestCase
def setup
@order = orders(:one)
end
def teardown
@order = nil
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:orders)
end
test "should get new" do
get :new
assert_response :redirect
end
test "should create order" do
assert_difference('Order.count') do
post :create, order: { address: @order.address, email: @order.email, name: @order.name, pay_type: @order.pay_type }
end
assert_redirected_to store_path
end
test "should show order" do
get :show, id: @order
assert_response :success
end
test "should get edit" do
get :edit, id: @order
assert_response :success
end
test "should update order" do
patch :update, id: @order, order: { address: @order.address, email: @order.email, name: @order.name, pay_type: @order.pay_type }
assert_redirected_to order_path(assigns(:order))
end
test "should destroy order" do
assert_difference('Order.count', -1) do
delete :destroy, id: @order
end
assert_redirected_to orders_path
end
test "requires item in cart" do
get :new
assert_redirected_to store_path
assert_equal flash[:notice], 'Your cart is empty'
end
test "should get new order" do
item = LineItem.new
item.build_cart
item.product = products(:ruby)
item.save!
binding.pry
session[:cart_id] = item.cart.id
get :new
binding.pry
assert_response :success
end
end
答案 0 :(得分:0)
您的测试方法名称似乎不正确。我相信你必须在方法名称之前添加test_
。
rake test test/controllers/orders_controller_test.rb -n test_should_get_new_order
# or
rake test test/controllers/orders_controller_test.rb - test_should_get_new_order
Rails将test 'some name' do
转换为test_some_name
以运行测试。