2013-05-08 54 views
0

我正在將我的用戶認證從頭開始轉換到設計寶石的過程。所有已完成,似乎工作正常。我改變了我的rspec測試,但我有一個反覆出現的問題,我已經尋找解決方案。轉換爲設計 - 水豚:: ElementNotFound:

的錯誤

2) AuthenticationPages authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page 
    Failure/Error: fill_in :email, with: user.email 
    Capybara::ElementNotFound: 
     cannot fill in, no text field, text area or password field with id, name, or label  'email' found 
    # (eval):2:in `fill_in' 
    # ./spec/requests/authentication_pages_spec.rb:53:in `block (5 levels) in <top (required)>' 

測試

describe "for non-signed-in users" do 
    let(:user) { FactoryGirl.create(:user)} 

    describe "when attempting to visit a protected page" do 
     before do 
      visit edit_user_registration_path(user) 

      fill_in "Email", with: user.email 
      fill_in "Password", with: user.password 
      click_button "Sign in" 
     end 

     describe "after signing in" do 
      it "should render the desired protected page" do 
       page.should have_selector('title', text: 'Edit user') 
      end 
     end 
    end 

的設計形式(new_user_session - 被允許看到編輯用戶信息出現之前)

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> 
    <%= f.label :email %> 
    <%= f.email_field :email, :autofocus => true %> 

    <%= f.label :password %> 
    <%= f.password_field :password %> 

    <% if devise_mapping.rememberable? -%> 
    <%= f.check_box :remember_me %> <%= f.label :remember_me %> 
    <% end -%> 

    <%= f.submit "Sign in", class: "btn btn-large btn-primary" %> 
<% end %> 
<%= render "devise/shared/links" %> 

在瀏覽器中測試時,該行爲實際上正常工作,但rspec測試失敗。

回答

0

水豚找不到電子郵件的輸入;由於表格看起來是正確的,所以水豚很可能在到達表格之前被重定向到另一頁。

您確定要跟隨表單的路徑是edit_user_registration_path(user)而不是例如new_user_registration_path或者(如果您正在測試sign_in而不是sign_up,則更好)new_user_session_path

+0

好,測試是針對當前未登錄的用戶嘗試訪問其編輯表單。它不應該允許這個,而是有一個簽名的形式(這是我附加的形式 - new_user_session)。用戶創建一個新的會話後,他們被重定向到他們最初打算去的編輯表單。然後測試應該驗證在視圖中登錄後應該顯示「編輯用戶」。在看到編輯表單之前,我無法讓水豚簽署用戶。 – 2013-05-08 17:31:02

+0

對不起@SeanL,我瞭解流程,你說得對。你能檢查什麼頁面到達水豚嗎?你的「訪問edit_user_registration_path(user)」步驟正在傳遞,所以它到達某處。 – Galen 2013-05-08 18:20:31

+0

我對水豚的去向感到相當困惑。我試着從fill_in(用戶信息)註釋中點擊按鈕 - 並更改測試的底部,看看頁面是否應該有h1,文本:'登錄'。它失敗說它登錄不顯示。網絡淨我不知道水豚要去哪裏。除非您有任何其他建議,否則我現在要放棄並評論測試。謝謝 – 2013-05-08 18:55:39

相關問題