2012-07-11 11 views
13

Ho un test RSpec che continua a non riuscire.RSpec dovrebbe avere_link non riesce nonostante esistano collegamenti

subject { page } 
visit user_path(user) 
it { should have_link('Settings', href: edit_user_path(user)) } 

Ma quando carico la pagina da sola, vedo che il collegamento funziona correttamente. Qualche idea ? Nessun errore di spelling pure.

È possibile visualizzare la pagina che RSpec ha caricato nel test?

risposta

15

Il tuo visit user_path(user) non è in esecuzione nel giusto contesto.

provare uno:

subject { page } 
it do 
    visit user_path(user) 
    should have_link('Settings', href: edit_user_path(user)) 
end 

Oppure:

subject { page } 
before { visit user_path(user) } 
it { should have_link('Settings', href: edit_user_path(user)) } 

Se volete vedere il codice HTML, è possibile utilizzare un'istruzione save_and_open_page.

Problemi correlati