How can I use rspec to check the contents of a text field 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 check the contents. Any suggestions?

This is a test I'm having problems 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 can do it all wrong, since I'm pretty new to TDD, but I see that this test passes when I remove a value from a text box that really confuses me. So is there a way to test a text field for its contents?

+6
source share
1 answer

Textures are different from input elements because their β€œvalue” is their content, not their value attribute, so should you map the content? Try the following:

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

Source: https://habr.com/ru/post/895119/


All Articles