My UsersControllerTest currently fails because I use verify_recaptcha in UsersController#create. How can I write my tests such that a known good CAPTCHA response is passed with params[:user]? I am using reCAPTCHA, but I suppose the question would apply to any CAPTCHA implementation.
Here is my UsersController#create
def create
@user = User.new(params[:user])
if verify_recaptcha(@user) && @user.save
flash[:notice] = "Account registered!"
redirect_to new_order_url
else
flash.now[:error] = "Account not registered!"
render :action => :new
end
end
and here is my functional test
test "should create user" do
assert_difference('User.count') do
post :create, :user => { :login => "jdoe",
:password => "secret",
:password_confirmation => "secret",
:first_name => 'john',
:last_name => 'doe',
:address1 => '123 Main St.',
:city => 'Anytown',
:state => 'XY',
:zip => '99999',
:country => 'United States',
:email => '[email protected]' }
end
end
This test fails as follows
4) Failure:
test_should_create_user(UsersControllerTest)
[(eval):3:in `each_with_index'
/test/functional/users_controller_test.rb:15:in `test_should_create_user']:
"User.count" didn't change by 1.
<3> expected but was
<2>.