Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I use Rspec to test the contents of a textarea in a view?

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?

like image 292
luis.madrigal Avatar asked Aug 16 '11 06:08

luis.madrigal


1 Answers

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')
like image 56
Steve Avatar answered Sep 21 '22 00:09

Steve