recursive_acronym
recursive_acronym

Reputation: 3031

capybara / rspec - something is nil... but what is it?

  it "should submit form", :driver => :webkit do
    visit '/things/new'
    page.should have_content('Login')
    fill_in 'user_login', with: @thing.email
    fill_in 'user_comment', with: @thing.comment
    click_button 'log_in'
    save_and_open_page
    page.should have_content('Thanks!')  
  end

response in browser [internal server error]:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

I'm guessing something in the things_controller or things/_form is unexpectedly nil, but I can't seem to nail down what it is. The page works fine in development (with populated database)

Is there a way to get more meaningful feedback?

or am I on the wrong track?

Upvotes: 2

Views: 562

Answers (2)

Fatlad
Fatlad

Reputation: 334

Check that your create function is not manually setting the createdf objects id and that any relations to that object are having their fields properly filled in.

I.e write tests that check these.

Are you using different db types?

Upvotes: 0

phoet
phoet

Reputation: 18835

there are several things you can do.

  • look into your logs/test.log
  • disable whiny nils and see if a real stack-trace pops up
  • use some introspection like a debugger or pry

or the hammer-method:

  • put a whole bunch of puts/Rails.logger.debug statements into your code

Upvotes: 3

Related Questions