6

I'm using Capybara with webkit for my testing, but for some reason when a test fails it shows the error, but not where it actually occurred in the code.

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)>'

and when using save_and_open_page it'll just show the error, with no information on where it occured:

Internal Server Error

undefined method `client_id' for # WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) at 127.0.0.1:60324

What I'm expecting to see is the line number and function where the error occured:

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

I can't seem to find anything related to this on Google. I'm probably using incorrect nomenclature. Anybody know how to fix this?

Constant Meiring
  • 3,285
  • 3
  • 40
  • 52
  • You've probably moved on ..but have you figured out the solution ? I have the same problem and can't find a solution – simha Jun 19 '13 at 19:34
  • Ah.. I just noticed that when I put js: true,it doesn't show me the exact error trace. When I remove the js:true, it shows me the exact line where error occured. – simha Jun 19 '13 at 19:37

2 Answers2

8

Basically capybara does not have a knowledge about the app, since it's running in the different process. You could workaround this problem using this a trick described here https://gist.github.com/1443408

luacassus
  • 6,540
  • 2
  • 40
  • 58
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.

Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82