运行rake测试时你好:函数,这是我在shell上得到的:
1) Failure:
test_should_create_client(ClientsControllerTest) [test/functional/clients_controller_test.rb:20]:
"Client.count" didn't change by 1.
<2> expected but was
<1>.
7 tests, 9 assertions, 1 failures, 0 errors
rake aborted!
Command failed with status (1): [/System/Library/Frameworks/Ruby.framework/...]
这就是我在clients_controller_test.rb文件中的第20行:
test "should create client" do
assert_difference('Client.count') do
post :create, :client => @client.attributes
end
请问有人可以告诉我问题的来源吗?
非常感谢nathanvda !!!!
我已将属性传递给测试并且它可以工作。这是'以下代码
test "should create client" do
assert_difference('Client.count') do
post :create, :client => {:name => 'jeff', :adress => 'ter', :city => 'ny',
:email =>'get@yahpp.fr', }
end
assert_redirected_to client_path(assigns(:client))
assert_equal 'Client was successfully created.', flash[:notice]
end
这是我在rake之后得到的:test:functionals:
Finished in 0.292246 seconds.
7 tests, 11 assertions, 0 failures, 0 errors
答案 0 :(得分:0)
可能由于您传递给控制器的属性中存在一些验证错误,因此没有创建新客户端。