Michael Hartl的Rails教程,7.3 Capybara :: ElementNotFound

时间:2013-05-23 20:17:49

标签: ruby-on-rails-3.2 railstutorial.org

我在Hartl's Rails教程的Section 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

“有效信息”和“无效信息”都失败,也许没有任何价值。

1 个答案:

答案 0 :(得分:0)

我不知道您是如何在Capybara中调用它但是尝试在提交按钮中添加ID并在Capybara中通过ID调用。 通过文档,您应该调用click_button method