Reputation:
Lets say I have the following form field:
<%= simple_form_for @page do |f| %>
<%= f.input :name, label: false, placeholder: "Name" %>
<%= f.button :submit %>
<% end %>
How can I test it's presence?
The following says no matches were found:
it { should have_field("name")}
Also tried "page[name]"
, which is the name given to the field in HTML, but then RSpec gives me this error:
it { should matcher }
RSpec expects the matcher to have a #description method. You should either
add a String to the example this matcher is being used in, or give it a
description method. Then you won't have to suffer this lengthy warning again.
Is it the square brackets that cause this? Thanks in advance.
Upvotes: 2
Views: 918
Reputation: 38645
What that message is saying is you are missing a description string for the example, which is because you only have it { should have_field("name")}
Update your example as follows:
it 'has name input field' { should have_field("page[name]")}
If you have multiple examples that may fall under same group then you can use describe
with it
as:
describe 'Page form' do
it 'has name input field' { should have_field("page[name]")}
it ... { ... }
end
Please reference Better Specs for other suggested best practices in working with RSpec.
Upvotes: 1
Reputation: 412
Providing that page is a subject:
it { should have_selector("form input[name='page[name]']") }
Upvotes: 1