I am writing a view spec with RSpec and I keep getting this problem. The test will find textarea but it fails when I try to test the contents. Any suggestions?
This is the test I am having trouble with.
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
I might be doing this all wrong since I am pretty new at TDD, but I am seeing that this test passes when I remove the value from the textarea which really confuses me. So is there a way to test a textarea for it's contents?
Textareas are different to input elements because their 'value' is their content rather than their value attribute, so should you be matching on the content instead? Try this:
f.should have_selector("textarea", :name => "reminder[content]", :content => 'The big content')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With