开发者

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

开发者 https://www.devze.com 2023-03-28 21:22 出处:网络
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?

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)开发者_如何学Python 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')
0

精彩评论

暂无评论...
验证码 换一张
取 消