Constant Meiring
Constant Meiring

Reputation: 3325

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?

Upvotes: 6

Views: 2025

Answers (2)

luacassus
luacassus

Reputation: 6720

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

Upvotes: 8

Chris Salzberg
Chris Salzberg

Reputation: 27374

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.

Upvotes: 3

Related Questions