hope@pikaqiu:~/rails/e/public$ rake test
(in /home/hope/rails/e)
DEPRECATION WARNING: Calling #scope or #default_scope with a hash is deprecated. Please use a lambda containing a scope. E.g. scope :red, -> { where(color: 'red') }. (called from <class:Product> at /home/hope/rails/e/app/models/product.rb:2)
Run options: --seed 48726
# Running tests:
....F..DEPRECATION WARNING: :confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: 'Text' }' instead. (called from block in _app_views_products_index_html_erb___112862662361393136_30081180 at /home/hope/rails/e/app/views/products/index.html.erb:24)
DEPRECATION WARNING: :confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: 'Text' }' instead. (called from block in _app_views_products_index_html_erb___112862662361393136_30081180 at /home/hope/rails/e/app/views/products/index.html.erb:24)
DEPRECATION WARNING: :confirm option is deprecated and will be removed from Rails 4.1. Use 'data: { confirm: 'Text' }' instead. (called from block in _app_views_products_index_html_erb___112862662361393136_30081180 at /home/hope/rails/e/app/views/products/index.html.erb:24)
...F.
Finished tests in 0.585706s, 20.4881 tests/s, 54.6349 assertions/s.
1) Failure:
ProductsControllerTest#test_should_create_product [/home/hope/rails/e/test/controllers/products_controller_test.rb:20]:
"Product.count" didn't change by 1.
Expected: 4
Actual: 3
2) Failure:
ProductsControllerTest#test_should_update_product [/home/hope/rails/e/test/controllers/products_controller_test.rb:39]:
Expected response to be a <redirect>, but was <200>
12 tests, 32 assertions, 2 failures, 0 errors, 0 skips
这里贴 test/controllers/products_controller_test.rb 的代码
require 'test_helper'
class ProductsControllerTest < ActionController::TestCase
setup do
@product = products(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:products)
end
test "should get new" do
get :new
assert_response :success
end
test "should create product" do
assert_difference('Product.count') do
post :create, product: { description: @product.description, image_url: @product.image_url, price: @product.price, title: @product.title } 此行有错误
end
assert_redirected_to product_path(assigns(:product))
end
test "should show product" do
get :show, id: @product
assert_response :success
end
test "should get edit" do
get :edit, id: @product
assert_response :success
end
test "should update product" do
patch :update, id: @product, product: { description: @product.description, image_url: @product.image_url, price: @product.price, title: @product.title }
assert_redirected_to product_path(assigns(:product))此行有错误
end
test "should destroy product" do
assert_difference('Product.count', -1) do
delete :destroy, id: @product
end
assert_redirected_to products_path
end
end
前辈解答一下吧:P