My UsersControllerTest is currently failing because I am using verify_recaptcha in UserController # create. How can I write my tests in such a way that the well-known good CAPTCHA answer is passed with the [: user] parameters? I am using reCAPTCHA, but I believe this question applies to any implementation of CAPTCHA.
Here is my UserController # 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 => ' jdoe@example.com ' } 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>.
source share