I'm trying to test the presence of a field called name within capybara but it returns the below error that is the follow:
1) _form filling the form filling the user elements
Failure/Error: fill_in 'name', with: 'Leo'
Capybara::ElementNotFound:
Unable to find field "name" that is not disabled
# /home/leo/.rvm/gems/ruby-2.6.4/gems/capybara-3.36.0/lib/capybara/node/finders.rb:303:in `block in synced_resolve'
# /home/leo/.rvm/gems/ruby-2.6.4/gems/capybara-3.36.0/lib/capybara/node/base.rb:83:in `synchronize'
# /home/leo/.rvm/gems/ruby-2.6.4/gems/capybara-3.36.0/lib/capybara/node/finders.rb:292:in `synced_resolve'
# /home/leo/.rvm/gems/ruby-2.6.4/gems/capybara-3.36.0/lib/capybara/node/finders.rb:53:in `find'
# /home/leo/.rvm/gems/ruby-2.6.4/gems/capybara-3.36.0/lib/capybara/node/actions.rb:91:in `fill_in'
# /home/leo/.rvm/gems/ruby-2.6.4/gems/capybara-3.36.0/lib/capybara/session.rb:778:in `block (2 levels) in <class:Session>'
# /home/leo/.rvm/gems/ruby-2.6.4/gems/capybara-3.36.0/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'
# ./spec/features/_form_spec.rb:9:in `block (3 levels) in <top (required)>'
Finished in 0.11537 seconds (files took 0.94126 seconds to load)
8 examples, 1 failure
Failed examples:
rspec ./spec/features/_form_spec.rb:7 # _form filling the form filling the user elements
Here is the spec that I'm trying to write:
# frozen_string_literal: true
require 'rails_helper'
RSpec.feature '_form', type: :feature do
context 'filling the form' do
scenario 'filling the user elements' do
visit users_path
fill_in 'name', with: 'Leo'
expect(page).to have_field('name', with: 'Leo')
end
end
end
And the form that I'm creating is like that:
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= form_with model: @user, local: true do |form| %>
<div>
<%= form.label :name %><br>
<%= form.text_field :name%>
<% @user.errors.full_messages_for(:title).each do |message| %>
<div><%= message %></div>
<% end %>
</div>
<div>
<%= form.label :email %><br>
<%= form.text_field :email %>
<% @user.errors.full_messages_for(:title).each do |message| %>
<div><%= message %></div>
<% end %>
</div>
<div>
<%= form.label :age %><br>
<%= form.text_field :age %>
<% @user.errors.full_messages_for(:title).each do |message| %>
<div><%= message %></div>
<% end %>
</div>
<div>
<%= form.submit %>
</div>
<% end %>
I tried all solutions here in S.O and none of them seem to work, can someone please help?
The project link is this one: https://github.com/LeoFragozo/leo_test, thanks in advance!
Edit: I tried to use user[name]/user_name in place of "name" in the fill_in and it dosen't seem to work as well.