2010-12-20 5 views
2

あなたがフォームを作成した場合は、captchaを持っています(私はヒューマナイザーの宝石を使用しています)。キュウリの特徴を書くときに、あなたはフォームを記入して、どのように期待した結果を出して得ますか?キャプチャ付きのキュウリの特徴

Scenario: Sign Up with Valid Data 
    Given I am not authenticated 
    And I am on the sign in page 
    When I follow "Sign up" 
    And I fill in the following: 
    | Name     | Administrator   |  
    | Email     | [email protected]   | 
    | Password    | 123456     | 
    | Password confirmation | 123456     | 
    And I fill in the captcha correctly 
    And I press "Sign Up" 
    Then I should be on the new_company page 
    And I should see "Hello Manoj" 

これで、ステップ定義を一致させることができます。/ ^私はcatchaを正しく$ $で埋め込むことができますか?

私はキュウリに慣れていて、これまでのところイライラしています。私はRailsやプログラミング以外では新しくない。

答えて

2

あなたは正しい、Aditya。環境依存コードをモデルに入れるのは良い解決策ではありません。しかし、あなたは「スタブ」bypass_humanizer?必要な場合:

# user.rb 
class User 
    include Humanizer 

    require_human_on :create, :unless => :bypass_humanizer? 

    protected 

    def bypass_humanizer? 
    false 
    end 
end 

# step definitions for your scenarion 
And /^I fill in the captcha correctly$/ do 
    # from now any instance of User class will skip require_human_on validator 
    User.any_instance.stubs(:bypass_humanizer?).returns(true) 
end 

# in Gemfile 
group :development, :test do 
    gem "mocha" 
end 

を今、あなたは環境に依存しないコードでモデルを持っていて、特定の状態にあなたが(テストのために、当然のことながら)必要がある時にそれを置くことができます。

2

私が見つけた1つの解決策は、Captchaがプロダクション環境でのみ追加されるようにすることでした。

ある程度、私はそれに満足しています。しかし、アプリケーションの環境に基づく分岐を減らすことが理想的です。

class User 
    ... 
    include Humanizer 
    if Rails.env.production? 
    require_human_on :create, :unless => :bypass_humanizer 
    end 
    ... 
end 
+0

はい、最も合理的な解決策です。 "と私は正しくcaptchaを記入してください:-)のステップの定義を想像してください –

+0

あなたはテストでのみ無効にしないでください?そうすれば、キャプチャはローカルでステージングを行います。 –

関連する問題