GSto
GSto

Reputation: 42350

Why does Capybara throw an error when the page works?

I have a very simple capybara script for a custom sign-up form using devise:

  scenario "allow me to register and should take me to the new partner page" do
    visit '/registrations/become_partner'
    response.should be_success
  end

When I try to run the test, I get the following error:

     ActionView::Template::Error:
       undefined method `first_name' for #<User:0x00000004d259e8>

even though this method is defined. I have the attr_accesible set in my model, the page renders, and I can call this method from the rails console. Why is capybara throwing this error when it is not a problem elsewhere?

Upvotes: 0

Views: 96

Answers (1)

Dennis Hackethal
Dennis Hackethal

Reputation: 14275

It looks like your test environment doesn't know that attribute yet - so apparently you have added the field first_name in your development environment, but not yet in your test environment.

To update your test environment, just run

rake db:test:prepare

and it will work. You should always do this after running a migration, it is a common error to run into.

Upvotes: 2

Related Questions