Rspec tests for administrative 'delete' links fail. Michael Hartl's ROR 3.2 Tutorial - Chapter 9.4.2
capybara, railstutorial.org, rspec, ruby-on-rails
Solution
You expect your `/users` page to contain the list of users with 'delete' link next to them. But you didn't fill your TEST db with simple users. It just contains one user, the admin. But according to your `users/_user.html.erb` this type of users doesn't have 'delete' link. So, add at least one user creation statement and try again.
Problem
I am following Michael's ROR tutorial and creating user authentication system. There is an admin privilige, which allows users to delete other users. Special 'delete' links appear on the users listing page when logged in as a priviliged admin user. My App works fine but rspec tests are failing for a reason unknown to me. I've separated the tests to another file `spec/requests/sat_spec.rb` and I am trying to use pry gem to debug it, but no success so far. ``` describe "delete links" do describe "as admin user" do let(:admin) { FactoryGirl.create(:admin) } before do sign_in admin visit users_path binding.pry end it { should have_link('delete', href: user_path(User.first)) } it "should be able to delete another user" do expect { click_link('delete') }.to change(User, :count).by(-1) end end ``` Test Failures: ``` 1) separated admin tests delete links as admin user Failure/Error: it { should have_link('delete', href: user_path(User.first)) } expected link "delete" to return something # ./spec/requests/sat_spec.rb:25:in `block (4 levels) in <top (required)>' 2) separated admin tests delete links as admin user should be able to delete another user Failure/Error: expect { click_link('delete') }.to change(User, :count).by(-1) Capybara::ElementNotFound: no link with title, id or text 'delete' found # (eval):2:in `click_link' # ./spec/requests/sat_spec.rb:28:in `block (5 levels) in <top (required)>' # ./spec/requests/sat_spec.rb:28:in `block (4 levels) in <top (required)>' ``` What might by the problem here or more importantly how to debug it? You can fork my code here https://github.com/tomek-rusilko/miniatury_katalog_2