Rspec请求说它找不到表单字段'帐户名'

时间:2012-02-25 23:50:09

标签: ruby-on-rails rspec

在我的rspec请求中,我做了:

将page.html

放入

我可以看到:

<label for="account_account_name">Account name</label>
<input id="account_name" name="account[name]" size="30" type="text" />

我的rspec请求:

require 'spec_helper'

describe "Account pages" do

  subject { page }

  describe "new" do

    before { visit account_new_path }

    describe "with valid information" do
      before do
        #puts page.html
        fill_in "Account name",       with: "acme inc."
        fill_in "Company name",       with: "acme inc."
        ..

      end

      it "should create a account" do
        expect { click_button "Create Account"}.to change(Account, :count).by(1)
      end
    end
  end
end

运行:

rspec spec/requests/account_pages_spec.rb

我收到错误:

1) Account pages new with valid information should create a account
     Failure/Error: fill_in "Account name",       with: "account name1"
     Capybara::ElementNotFound:
       cannot fill in, no text field, text area or password field with id, name, or label 'Account name' found
     # (eval):2:in `fill_in'
     # ./spec/requests/account_pages_spec.rb:14:in `block (4 levels) in <top (required)>'

为什么找不到该元素?

再次输出了前一个块中的page.html,它确实输出了我粘贴在上面的正确的html。

2 个答案:

答案 0 :(得分:1)

标签的for属性无法正确识别输入字段。

答案 1 :(得分:0)

请试试这个:

fill_in "account[name]", :with => "acme inc."