为什么功能测试失败?
您好,当运行 rake test:functions 时,这是我在 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 =>'[email protected]', }
end
assert_redirected_to client_path(assigns(:client))
assert_equal 'Client was successfully created.', flash[:notice]
end
这是我得到的结果耙子:测试:功能:
Finished in 0.292246 seconds.
7 tests, 11 assertions, 0 failures, 0 errors
Hello when run rake test:functionals, here's what I get on the 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/...]
and this is what I have on line 20 in the clients_controller_test.rb file:
test "should create client" do
assert_difference('Client.count') do
post :create, :client => @client.attributes
end
Please can anyone tell me where the problem comes from?
Thank you so much nathanvda!!!!
I have pass the attributes to the test and it works.Here' the following code
test "should create client" do
assert_difference('Client.count') do
post :create, :client => {:name => 'jeff', :adress => 'ter', :city => 'ny',
:email =>'[email protected]', }
end
assert_redirected_to client_path(assigns(:client))
assert_equal 'Client was successfully created.', flash[:notice]
end
Here's what I get after rake:test:functionals:
Finished in 0.292246 seconds.
7 tests, 11 assertions, 0 failures, 0 errors
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是由于您传递给控制器的属性中存在一些验证错误,因此没有创建新的客户端。
Probably, due to some validation error in the attributes you pass to the controller, there was no new client created.