为什么功能测试失败?

发布于 2024-12-04 12:19:39 字数 1406 浏览 0 评论 0原文

您好,当运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2024-12-11 12:19:39

可能是由于您传递给控制器​​的属性中存在一些验证错误,因此没有创建新的客户端。

Probably, due to some validation error in the attributes you pass to the controller, there was no new client created.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文