2011-01-24 85 views
1

我使用的設計進行用戶認證,並具有以下黃瓜失敗失敗的情況:登錄測試與設計和黃瓜

Scenario: Log in to the system 
    Given a user called "test" with a password of "secret" 
    And I am not logged in # Just visits /users/sign_out 
    When I go to the log in page 
    And I fill in "user_username" with "test" 
    And I fill in "user_password" with "secret" 
    And I press "Sign in" 
    Then I should see "Signed in successfully." 

如果我堅持一個「那麼告訴我的頁面」的結尾我」 m顯示了一個空白日誌形式的頁面。

以下(非常相似)的測試原理:

Scenario: Fail to log in with invalid credentials 
    Given a user called "test" with a password of "secret" 
    And I am not logged in 
    When I go to the log in page 
    And I fill in "user_username" with "test" 
    And I fill in "user_password" with "invalid password" 
    And I press "Sign in" 
    Then I should see "Invalid email or password." 

...所以我假設在日誌中做了重定向驗證成功,黃瓜不繼後(FWIW在日誌中所有的作品,當我在瀏覽器中手動執行)...任何人都可以告訴我如何通過測試?

感謝, 灰

編輯:「(在簽名成功」),這是一個與一個?預計#has_content「失敗的最後一步返回true,得到了假」的錯誤(...啊哈。 ..應該在前面提到過!)

回答

1

修好了!我剛剛將我的服務器加載到測試環境中,並重現了問題。

我正在使用ldap_authenticatable和config.ldap_create_user = true。在用戶帳戶的第一個日誌中,如果它不存在(它不在最新擦除的測試數據庫中),則會創建該日誌,但是這會重新導向登錄頁面而不是根目錄路徑。後續登錄執行預期的行爲。所以下面的測試通過:

Scenario: Log in to the system 
    Given a user called "test" with a password of "secret" 
    And I am not logged in 
    When I go to the log in page 
    And I fill in "user_username" with "test" 
    And I fill in "user_password" with "secret" 
    And I press "Sign in" 
    And I fill in "user_username" with "test" 
    And I fill in "user_password" with "secret" 
    And I press "Sign in" 
    Then I should see "Signed in successfully." 

非常感謝pjammer橡膠鴨!

1

是id字段user_username或者是user_email什麼的?

還有什麼當我去登錄頁面看起來像?你確定你去那裏?

+0

是的,他們是外地ID。我不認爲它在這方面存在問題 - 另一項測試正在通過,所以我知道他們正在爲正常工作而正確填寫。 「當我進入登錄頁面」是一個Capybara步驟,在paths.rb中添加了「登錄頁面」。再次,不要認爲這是問題 - 我無法擺脫那個頁面,因此它顯示在「向我顯示頁面」! – Ash 2011-01-24 15:13:35

+1

和測試用戶的祕密(我知道你混淆了),但該夾具或工廠也存在? – pjammer 2011-01-24 15:20:32