6

我正在使用 Capybara 和 webkit 进行测试,但由于某种原因,当测试失败时,它会显示错误,而不是代码中实际发生的位置。

Failures:

  1) online shopping -  sign up
     Failure/Error: page.should have_content 'Payment added successfully'
       expected there to be content "Payment added successfully" in "Internal Server Error undefined method `client_id' for #<InvoicePayment:0x007fbd5b834008> WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) at 127.0.0.1:60324"
     # ./spec/requests/online_shopping_spec.rb:140:in `block (2 levels) in <top (required)>'

并且在使用save_and_open_page时只会显示错误,没有关于它发生的位置的信息:

内部服务器错误

#WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) 在 127.0.0.1:60324 的未定义方法“client_id”

我期望看到的是发生错误的行号和函数:

app/controllers/invoices_controller.rb:30:in `show'

我似乎在 Google 上找不到与此相关的任何内容。我可能使用了不正确的命名法。有人知道如何解决这个问题吗?

4

2 回答 2

8

基本上水豚对应用程序一无所知,因为它在不同的进程中运行。您可以使用此处描述的技巧解决此问题https://gist.github.com/1443408

于 2013-01-09T10:22:03.857 回答
3

The problem is that the actual page is not rendering because of an error, and instead you are getting an internal server error. So Internal Server Error undefined method... is the content of the page you are testing. RSpec/Capybara can't tell you where it occurred because the test framework only tests what you actually see on the page, and that is exactly what you see (as you confirmed when you ran save_and_open_page).

To track down the error you should look at your rails error log, or the console/terminal where you are running it from. Without more information I can't help you track down the error.

Hope that helps.

于 2013-01-06T00:19:38.377 回答