2
votes

I'm creating a test and I'm having a problem with an ambiguous match on my sign up page. On my nav bar I have a drop down to login with email and password fields. On my sign up page I have a text field called email. So I have two email fields.

<%=f.label :email%>
<%=f.text_field :email  %>

If I rename one of the forms label that's associated with the email field to something different I still get the error. I also tried setting the id of one of the fields to something different but it gave the same error. I'm not sure how to make them not interfere with each other on the test. The page in the browser works fine.

Test:

describe "signup" do 
before {visit signup_path}
let(:submit) { "Create Account"}
describe "with valid information" do

  before do

        fill_in "Name",         with: "Example User"
        fill_in 'Email',        with: "[email protected]"
        fill_in "Password",     with: "password"
        fill_in "Confirmation", with: "password"
    end

    it "should create a user" do
        expect { click_button submit}.to change(User, :count).by(1)
    end
end

View partial for the dropdown, This in in a nav section in the application layout with a couple other links. No other fields.

<%= form_for(:session, url: sessions_path) do |f| %>

  <%=f.label :email%>
  <%=f.text_field :email  %>

  <%= f.label :password %>
  <%= f.password_field :password %>

  <%= f.submit "Sign In", class: "btn btn-small btn-primary" %>
<% end %>

Sign Up page View:

<div class="row">
<div class="span6 offset3">
    <%= form_for(@user) do |f| %>
        <%= render 'shared/error_messages' %>
        <%= f.label :name %>
        <%= f.text_field :name %>

        <%= f.label :email %>
        <%= f.text_field :email  %>

        <%= f.label :password %>
        <%= f.password_field :password %>

        <%= f.label :password_confirmation, "Confirmation" %>
        <%= f.password_field :password_confirmation %>

        <%= f.submit "Create Account", class: "btn btn-primary" %>
    <% end %>
</div>
</div>
1
Can you include the test and more of the view to see what other selectors might be available to use to narrow the scope, e.g. through a within block in Capybara test.mdenomy
Sure. I edited it to include the test and more of the view.Matthew

1 Answers

2
votes

You should use within block (example)

before do
  within(".row .span6") do

    fill_in "Name",         with: "Example User"
    fill_in 'Email',        with: "[email protected]"
    fill_in "Password",     with: "password"
    fill_in "Confirmation", with: "password"
  end
end

Or maybe you have a better css class for your form