Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 660053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:06:50+00:00 2026-05-13T23:06:50+00:00

My UsersControllerTest currently fails because I use verify_recaptcha in UsersController#create. How can I write

  • 0

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 => '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>.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:06:50+00:00Added an answer on May 13, 2026 at 11:06 pm

    Try using flexmock or mocha to have all instances of verify_recaptcha return true:

    This line in my app made the create test pass without a problem on my app:

    flexmock(User).new_instances.should_receive(:verify_recaptcha).and_return(true)
    

    If you add this line before the “create” action takes place it should work.

    Also, I haven’t tried out this recaptcha plugin, but this might also be of help for you:
    http://www.fromdelhi.com/2006/07/21/rails-captcha-and-testing-using-mock-objects/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following example, can I use build() instead of create() ? class UsersControllerTest
For my Rails 3 application I use FactoryGirl together with shoulda context (1.0.0.beta1) and
I created a module in lib directory and I can freely call the various
How can I echo a html/xml output from a controller action in my test
A question about how to use test-mvc for unit testing. I have a simple
I'm stumped on what's causing this. I get this error and stack trace in
I'm trying to test a controller and I got this error. I understand the
I'm building an app in Rails 3 using Authlogic for authentication. I have a
I'm having an issue with assertRedirectTo() in a test I have created, below is
I am working through a Grails tutorial from InfoQ called Getting Started With Grails,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.