lundi 2 février 2015

Capybara can't find user for delete action

I'm using RSpec (v. 3.1.0) and Capybara (v. 2.4.3) to test my Rails 4 application. My user delete spec.rb contains the following code:



it "is successful when clicking the destroy link" do
visit "/users"
save_and_open_page
within "#user_#{user.id}" do
click_link "Destroy"
end

expect(page).to have_content("User was successfully destroyed.")


Capybara throws the following error:



1) Deleting User is successful when clicking the destroy link
Failure/Error: within "#user_#{user.id}" do
Capybara::ElementNotFound:
Unable to find css "#user_509"


Save_and_open_page shows FactoryGirl created a user for the test. The error message indicates the user's id is 509. My program's code (delete method) works as expected, so the problem appears to be my test code. What can I do to help Capybara find the user? Thanks for any help!


Aucun commentaire:

Enregistrer un commentaire