0

我在Hartl's Rails 教程的第 7.3.1 节中,并收到以下错误:

Capybara::ElementNotFound:
   no button with value or id or text 'Create my account' found

但据我所知,具有该值的按钮确实存在。

这是 new.html.erb 代码:

<div class="row">
    <div class="span6 offset3">
        <%= form_for(@user) do |f| %>



            <%= 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 my acccount", class: "btn btn-large btn-primary" %>
        <% end %>
    </div>
</div>

有人在这里有什么想法吗?

另外,这是测试的一部分:

describe "signup" do

    before { visit signup_path }

    let(:submit) { "Create my account" }

    describe "with invalid information" do
      it "should not create a user" do
        expect { click_button submit }.not_to change(User, :count)
      end
    end

    describe "with valid information" do
      before do
        fill_in "Name",         with: "Example User"
        fill_in "Email",        with: "user@example.com"
        fill_in "Password",     with: "foobar"
        fill_in "Confirmation", with: "foobar"
      end

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

“具有有效信息”和“具有无效信息”都失败了也可能一文不值。

4

1 回答 1

0

我不知道您如何在 Capybara 中调用它,但尝试将 ID 添加到提交按钮并在 capybara 中通过 ID 调用。根据文档,您应该调用click_button 方法

于 2013-05-23T21:33:48.073 回答