2010-12-20 2 views
2

양식에 captcha가있다면 (나는 humanizer 보석을 사용하고 있습니다). 오이 특징을 쓸 때 어떻게 양식을 채우고 보내고 기대 한 결과를 얻는가?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

그래서 Captcha가 프로덕션 환경에만 추가되었는지 확인하는 한 가지 해결책이 있습니다.

어느 정도까지 나는 그것에 만족합니다. 그러나 앱에서 환경 기반 분기를 줄이는 것이 이상적입니다.

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

예, 가장 합리적인 해결책입니다. "그리고 나는 정확하게 captcha를 채 웁니다.":-) –

+0

당신은 테스트에서만 그것을 disable하지 않습니까? 그런 식으로 captcha는 로컬 및 스테이징에서 작동합니다. –