What is the difference between rspec have_css, has_selector and has_field?

I have this html.erb Rails form:

<h1 class=new_vendor_header>New Vendor Form</h1> <%= form_for(@vendor) do |f| %> <%= f.label :name %> <%= f.text_field :name, placeholder: "ex: Jeff" %> <%= f.submit "Submit" %> <% end %> 

It goes through:

 expect(page).to have_selector('input[placeholder="ex: Jeff"]') 

But this is not so:

 expect(page).to have_field('input[placeholder="ex: Jeff"]') 

and this is not so:

 expect(page).to have_selector('input[placeholder="ex: Jeff"]') 

The selector refers to the HTML selector on the right, so does it refer to html elements? have_css I thought they were looking for CSS, but it seems to be doing more. Here is an example from the cover:

 response.body.should have_css("input", :count => 3) #True if there are 3 input tags in response 

And this is similar to HTML input selectors.

So what is the difference and why the other two do not work in my example?

+5
source share
1 answer

From Docs here, have_css will call has_selector with css as a parameter, since has_selector can handle css , xpath , ...

 def have_css(css, options={}) HaveSelector.new(:css, css, options) end 
+4
source

All Articles