1

最初にメールアドレスとパスワードを要求し、次に[a-zA-Z0-9]を含む2つの選択リストをユーザーに提示する2段階のログインシステムをテストする必要があります。ドロップダウンの横のラベルは、「セキュリティフレーズから文字Xを選択」の形式です。ここで、Xは既知のセキュリティフレーズからのランダムな文字インデックスです。

検収試験のためにコードをスタブしたくないので、キュウリでマッチャーを書くことは可能ですか?それは、フレーズ全体を知っているので、2つのリストのそれぞれで必要な文字を選択しますか?

これまでのシナリオと関連する手順は次のとおりです。

Scenario: valid login email, password and secret phrase takes me to the dashboard
  Given I am not logged in
  When I log in as "admin@example.com"
  Then I should be on the dashboard page
  And I should see "Your Dashboard"

When /^I log in as "([^\"]*)"$/ do |login|
  visit path_to('Login page')
  fill_in "Email", :with => login
  fill_in "Password", :with => "Password123"
  click_button "Log in"
  response.should contain("Please verify some characters from your security phrase")
  select "a", :from => "Select character X of your security phrase"
  select "b", :from => "Select character Y of your security phrase"  
  click_button "Submit"
end

たとえば、セキュリティフレーズが「Secret123」、X = 3、Y = 8の場合、上記は次と同等のものを生成する必要があります。

select "c", :from => "Select character 3 of your security phrase"
select "2", :from => "Select character 8 of your security phrase"

実際のページの番号XとYは、それぞれspan#svc_1とspan#svc_2の中にあります。

ありがとう、

4

1 に答える 1

1

いろいろ悩んだ末、やっとわかりました。同じ状況にある他の人を助けることができるように、ここに文書化します。general_steps.rb では:

When /^I log in as "([^\"]*)"$/ do |email|
  visit path_to('Login page')
  fill_in "Email", :with => email
  fill_in "Password", :with => "password"
  click_button "Log in"
  response.should contain("Please verify some characters from your secret phrase")
  select_correct_secret_phrase_char("span#sec_1")
  select_correct_secret_phrase_char("span#sec_2")
  click_button "Submit"
end

def select_correct_secret_phrase_char(css_selector)
  response.should have_selector(css_selector) do |scope|
    select "Secret1"[(scope.text.to_i)-1].chr, :from => "Select character #{scope.text} of your security phrase"
  end
end
于 2010-05-18T15:19:40.433 に答える