Why is RSpec/Capybara not showing where errors occured
Asked Answered
D

2

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?

Distilled answered 5/1, 2013 at 23:54 Comment(2)
You've probably moved on ..but have you figured out the solution ? I have the same problem and can't find a solutionSeriate
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.Seriate
M
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

Mulder answered 9/1, 2013 at 10:22 Comment(1)
Thanks, that link looks promising!Distilled
S
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.

Showbread answered 6/1, 2013 at 0:19 Comment(1)
What's weird is that on the other application I'm working on, it says in the terminal exactly the line number where it breaks!Distilled

© 2022 - 2024 — McMap. All rights reserved.