2012-02-25 94 views
1

在我的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。

+0

对属性的标签的不正确识别输入字段。 – 2012-02-26 20:05:22

回答

1

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

+0

是的我也有帐户名称,我剪掉/粘贴了错误的html。我更新了html谢谢。 – Blankman 2012-02-26 00:13:17

0

请试试这个:

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