Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is RSpec/Capybara not showing where errors occured

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?

like image 793
Constant Meiring Avatar asked Jan 05 '13 23:01

Constant Meiring


2 Answers

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

like image 179
luacassus Avatar answered Nov 14 '22 23:11

luacassus


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.

like image 39
Chris Salzberg Avatar answered Nov 15 '22 00:11

Chris Salzberg