2011-01-28 3 views
0

Ruby와 Cucumber는 처음이지만 웹 앱의 고급 기능을 테스트하는 데 사용하고 있습니다. 나는 그것이 어떻게 작동하는지에 대한 아이디어를 대부분 가지고 있지만, 나는 하나의 비트로 고심하고있다. 사용자가 로그인 감안할 때이 단계는 다음과 같습니다 : 내가 말할 수있는 시나리오 파일의 배경을 사용하고루비/오이로 로그인

Given /^I am logged in as "([^"]*)" with password "([^"]*)"$/ do |user, password| 
    visit "http://www.website.com:82/login" 

    #Is there a 'logout'? 
    if (response_body contain('Login')) then 
    fill_in "email", :with => user 
    fill_in "password", :with => password 
    click_button "Login" 
    end 
    response_body.should contain("Your Accounts") 
end 

나는 경우에 문제가 있어요. 나는 '로그인하지 않았다면 로그인하십시오.'라고 말하고 싶지만 webrat 객체를 사용할지를 확신하지 못합니다 (response_body가 무엇인지) 아니면 다른 것입니다.

감사

마이크

답변

1

(약간 던지는 것보다 나에게 지워 보인다 조건부 오이) :

Given /^I am logged in as "([^"]*)" with password "([^"]*)"$/ do |user, password| 
    visit destroy_session_path # make sure you are logged out 

    visit "http://www.website.com:82/login" 
    fill_in "email", :with => user 
    fill_in "password", :with => password 
    click_button "Login" 

    response_body.should contain("Your Accounts") 
end 
0

그래서,이 그것을 변경하고 일 : 아마 같은 갔다했을 것이다

Given /^I am logged in as "([^"]*)" with password "([^"]*)"$/ do |user, password| 
    visit "http://www.website.com:82/login" 

    #Is there a 'logout'? 
    if (response_body.match('Login')) then 
    fill_in "email", :with => user 
    fill_in "password", :with => password 
    click_button "Login" 
    end 
    response_body.should contain("Your Accounts") 
end