2011-08-16 7 views
6

Sto scrivendo una specifica di visualizzazione con RSpec e continuo ad avere questo problema. Il test troverà textarea ma fallisce quando provo a testare il contenuto. Eventuali suggerimenti?come utilizzare Rspec per verificare il contenuto di una textarea in una vista?

Questo è il test con cui ho problemi.

describe "reminders/edit.html.erb" do 
    before(:each) do 
    @reminder = Factory(:reminder) 
    end 

    it "should render the form to edit a reminder" do 
     assign :reminder, @reminder 
     render 
     rendered.should have_selector("form", :method => "post", :action => reminder_path(@reminder)) do |f| 
     f.should have_selector("input", :type => "text", :name => "reminder[title]", :value => "The Title" ) 
     f.should have_selector("textarea", :name => "reminder[content]", :value => 'The big content') 
     f.should have_selector("input", :type => "submit") 
     end 

end 

Potrei fare tutto questo torto dal momento che sono abbastanza nuovo a TDD, ma sto vedendo che questo test viene superato quando rimuovo il valore del textarea che in realtà mi confonde. Quindi c'è un modo per testare una textarea per i suoi contenuti?

risposta

8

Le aree di testo sono diverse rispetto agli elementi di input perché il loro "valore" è il loro contenuto piuttosto che il loro attributo di valore, quindi dovresti essere corrispondente sul contenuto? Prova questo:

f.should have_selector("textarea", :name => "reminder[content]", :content => 'The big content') 
+0

Grazie, il cappello ha funzionato perfettamente! Ed è esattamente quello che stavo cercando. –

+3

Penso che ': content' ora sia': text' – aceofspades

Problemi correlati