2011-02-03 8 views
0

私はこれを持っている:ファクトリーガールとキュウリとカピバラを使用すると、どのようにフォームに入力できますか?

Scenario: Login 
    Given a user exists with first_name: "Fred" 
    When I am on the home page 
    And I fill in "email" with the user: "Fred" 
    And I fill in "password" with the user: "Fred" 
    And I submit the form 
    Then I should see "Welcome" 

問題は、私はファクトリー・ガール、生成されたユーザーの電子メールが移入emailフィールドを得るのですかですか?私もpickleを使用していますがfill inのためのステップがありません

sequence(:email) {|n| "joeschmoe#{n}@example.com"} 

:それはシーケンスとして定義されていますので、メールは一意でなければなりません。工場でユーザーを作成し、同じユーザーの情報でログインフォームに記入するにはどうすればよいですか?

答えて

1

私はこれにそれを変更し、次のステップの定義では

Scenario: Login 
    Given a user exists with email: "[email protected]", plain_password: "password", plain_password_confirmation: "password" 
    And I am on the home page 
    When I login with "[email protected]", "password" 
    And I submit the form 
    Then I should see "Welcome" 

When(/^I login with "(\S+)", "(.*)"$/) do |email, password| 
    fill_in 'username', :with => email 
    fill_in 'plain_password', :with => password 
end 

# Can only be executed with Selenium or Envjs drivers 
When /^I submit the form$/ do 
    page.evaluate_script("document.forms[0].submit()") 
end 

そして、それは働きます!

1

あなた自身のステップを追加する必要があります。

When /^(?:|I)fill in "([^"]*)" with the #{capture_model}(?: within "([^"]*)")?$/ do |field, a, selector| 

    with_scope(selector) do 
    fill_in(field, :with => model!(a).send(field)) 
    end 
end 
+0

私はこれを認識しますが、capture_modelの属性にはどのようにアクセスしますか? –

+0

pickleを使用している場合は、capture_modelにアクセスできます。あなたはモデルを見ることができました!(a)。これはハンドラを見つける。 – kriysna

+0

モデル!(a).send(field)=>ハンドラと属性を持つモデルを検索します。 user_with_handle.email、field = 'email'、a = 'fredという名前のユーザー'、これはUser.where(:first_name => 'fred')と同様です。 – kriysna

関連する問題