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 5999201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:31:08+00:00 2026-05-23T00:31:08+00:00

This is from Michael Hartl’s book, section 8.4. RSpec is testing a successful signup

  • 0

This is from Michael Hartl’s book, section 8.4. RSpec is testing a successful signup but is fails because the email address isn’t unique. So if I go into the code and update the email address in the spec, it works the first time I run it but not the second time. I have confirmed this because I can make the test pass by changing the email address or otherwise running rake db:test:clone.

Any thoughts on how to overcome this would be appreciated.

Code:
require ‘spec_helper’

describe "Users" do
  describe "signup" do
    describe "failure" do
      it "should not make a new user" do
        lambda do
          visit signup_path
          fill_in :user_name,               :with => "" #you can use CSS id instead of label, which is probably better
          fill_in "Email",                  :with => ""
          fill_in "Password",               :with => ""
          fill_in "Password confirmation",  :with => ""
          click_button
          response.should render_template('users/new')
          response.should have_selector("div#error_explanation")
        end.should_not change(User, :count)
      end
    end
    describe "success" do
      it "should make a new user" do
        lambda do
          visit signup_path
          fill_in "Name",                   :with => "Example User"
          fill_in "Email",                  :with => "alex@example.com"
          fill_in "Password",               :with => "foobar"
          fill_in "Password confirmation",  :with => "foobar"
          click_button
          response.should have_selector("div.flash.success", :content => "Welcome")
          response.should render_template('users/show')
        end.should change(User, :count).by(1)
      end
    end 
  end
end
  • 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-23T00:31:08+00:00Added an answer on May 23, 2026 at 12:31 am

    What does your spec/spec_helper.rb file look like? Do you have transactions turned on?

    RSpec.configure do |config|
      config.use_transactional_fixtures = true
    end
    

    This runs each of your specs within a database transaction, returning it back to its original state after each test run.

    Once your spec helper looks something like that, run:

    rake db:test:prepare
    

    And try again. If that doesn’t work, can you provide any more information? Which version of RSpec? Which version of Rails?

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

Sidebar

Related Questions

This question follows on from the answer given by Michael Pilat in Preventing Plus
I see this from time to time and want to know what it is.
I've got a couple django models that look like this: from django.contrib.sites.models import Site
Are there any compatibility issues that would prevent this from working? Do I need
Supposedly, it is possible to get this from Google Maps or some such service.
Using instance methods as callbacks for event handlers changes the scope of this from
I've been searching around, and I haven't found how I would do this from
Just for review, can someone quickly explain what prevents this from working (on compile):
I have a JavaScript function, pop_item . I have to call this from PHP,
This page from Adobe says to add a wmode parameter and set its value

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.