2011-09-08 51 views
3

所以我有該規範水豚:FILL_IN動作定位器

describe "visit /signup" do 
    before(:each) do 
     get signup_path 
    end 
    it "has an email input field" do 
     page.has_field?("#user_email") 
    end 
    it "accepts an email address" do 
     page.fill_in('#user_email', :with=>Faker::Internet.email) 
    end 
end 

第一個測試(已經電子郵件輸入)通過,所述第二失敗

Failure/Error: page.fill_in('#user_email', :with=>Faker::Internet.email) 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label '#user_email' found 

輸入[類型=「文本」 ]元素存在於具有該DOM ID的頁面上,嘗試使用帶和不帶散列的ID進行定位,並將其輸入:name用作定位符。

我在做什麼錯?

+0

'save_and_open_page'在調試時也非常有用 – oliyoung

回答

3

這是因爲你使用get時,你應該使用visitbefore塊內。這:

before(:each) do 
    get signup_path 
end 

應該是這樣的:

before(:each) do 
    visit signup_path 
end 

否則你告訴Rack::Test參觀這條道路,水豚!一個小小的區別就是經常出現很多人!

0

我認爲fill_in不在頁面上。只需使用FILL_IN:

describe "visit /signup" do 
    before(:each) do 
     get signup_path 
    end 
    it "has an email input field" do 
     page.has_field?("#user_email") 
    end 
    it "accepts an email address" do 
     fill_in('#user_email', :with=>Faker::Internet.email) 
    end 
end 
2

也許你應該刪除#,例如

fill_in('user_email', :with=>Faker::Internet.email)