2010-08-16 72 views
6

我有一個黃瓜步:假設我登錄黃瓜步驟定義「由於我登錄」

我不明白,我應該如何實現它作爲一個步驟定義。

可能有人點我到正確的方向,教程,博客等

+1

需要知道你使用的是什麼認證系統 – 2010-08-16 19:50:34

回答

9

這裏是我如何做到這一點。

Given /^I have one\s+user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username,email, password| 
    @user = User.new(:email => email, 
        :username=>username, 
        :password => password, 
        :password_confirmation => password) 
    @user.save! 
end 

Given /^I am an authenticated user$/ do 
    name = 'exmample' 
    email = '[email protected]' 
    password = 'secret!' 

    Given %{I have one user "#{name}" with email "#{email}" and password "#{password}"} 
    And %{I go to the user login page} 
    And %{I fill in "user_username" with "#{name}"} 
    And %{I fill in "user_password" with "#{password}"} 
    And %{I press "Sign in"} 
end 

我這樣做的原因,是我在整個堆棧上運行,並設置環境方式有普通用戶將...

4

嗨,您可以將這個步驟分爲三個較小的步驟

1. visit login page 
2. fill_in login, username 
3. press login button