Skip to content

Commit

Permalink
Tests for timeout, ad8bbbb
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason L Perry committed Sep 15, 2009
1 parent ad8bbbb commit 6eda6f6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions test/verify_recaptcha_test.rb
Expand Up @@ -49,10 +49,7 @@ def test_errors_should_be_added_to_model

errors = mock
errors.expects(:add).with(:base, "Captcha response is incorrect, please try again.")

model = mock(:class => mock(:name => mock(:underscore => 'foo')))
model.expects(:valid?)
model.expects(:errors).returns(errors)
model = mock(:valid? => false, :errors => errors)

assert !@controller.verify_recaptcha(:model => model)
assert_equal "bad-news", @controller.session[:recaptcha_error]
Expand All @@ -67,7 +64,13 @@ def test_returns_true_on_success_with_optional_key
assert @controller.verify_recaptcha(:private_key => 'ADIFFERENTPRIVATEKEYXXXXXXXXXXXXXX')
assert_nil @controller.session[:recaptcha_error]
end


def test_timeout
expect_http_post(Timeout::Error, :exception => true)
assert !@controller.verify_recaptcha()
assert_equal "recaptcha-not-reachable", @controller.session[:recaptcha_error]
end

private

class TestController
Expand All @@ -79,8 +82,12 @@ def initialize
end
end

def expect_http_post(response)
Net::HTTP.expects(:post_form).with(@expected_uri, @expected_post_data).returns(response)
def expect_http_post(response, options = {})
unless options[:exception]
Net::HTTP.expects(:post_form).with(@expected_uri, @expected_post_data).returns(response)
else
Net::HTTP.expects(:post_form).raises response
end
end

def response_with_body(body)
Expand Down

0 comments on commit 6eda6f6

Please sign in to comment.