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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:13:59+00:00 2026-06-17T15:13:59+00:00

I keep getting this error when I run rspec: Sequence not registered: email. However,

  • 0

I keep getting this error when I run rspec: Sequence not registered: email.

However, I did set it in my factories.rb file. Any ideas on how to fix this? The app is running fine.

Failures:

  1) UsersController GET 'index' for signed-in-users should be successful
     Failure/Error: @users << Factory(:user, :email => Factory.next(:email))
     ArgumentError:
       Sequence not registered: email
     # ./spec/controllers/users_controller_spec.rb:28:in `block (5 levels) in <top (required)>'
     # ./spec/controllers/users_controller_spec.rb:27:in `times'
     # ./spec/controllers/users_controller_spec.rb:27:in `block (4 levels) in <top (required)>'

  2) UsersController GET 'index' for signed-in-users should have the right title
     Failure/Error: @users << Factory(:user, :email => Factory.next(:email))
     ArgumentError:
       Sequence not registered: email
     # ./spec/controllers/users_controller_spec.rb:28:in `block (5 levels) in <top (required)>'
     # ./spec/controllers/users_controller_spec.rb:27:in `times'
     # ./spec/controllers/users_controller_spec.rb:27:in `block (4 levels) in <top (required)>'

  3) UsersController GET 'index' for signed-in-users should have an element for each user
     Failure/Error: @users << Factory(:user, :email => Factory.next(:email))
     ArgumentError:
       Sequence not registered: email
     # ./spec/controllers/users_controller_spec.rb:28:in `block (5 levels) in <top (required)>'
     # ./spec/controllers/users_controller_spec.rb:27:in `times'
     # ./spec/controllers/users_controller_spec.rb:27:in `block (4 levels) in <top (required)>'

  4) UsersController GET 'index' for signed-in-users should paginate users
     Failure/Error: @users << Factory(:user, :email => Factory.next(:email))
     ArgumentError:
       Sequence not registered: email
     # ./spec/controllers/users_controller_spec.rb:28:in `block (5 levels) in <top (required)>'
     # ./spec/controllers/users_controller_spec.rb:27:in `times'
     # ./spec/controllers/users_controller_spec.rb:27:in `block (4 levels) in <top (required)>'

Finished in 2.88 seconds
80 examples, 4 failures

factories.rb:

Factory.define :user do |user|
    user.name "Pavan Katepalli"
    user.email "email@pavan.com"
    user.password "foobar"
    user.password_confirmation "foobar"
end

Factory.sequence :email do |n|
  "person-#{n}@example.com"
end

users_controller_spec.rb:

require 'spec_helper'

describe UsersController do

    render_views

    describe "GET 'index'" do
        # book's way is on page 386 
        # I used the repo's way
        describe "for non-signed-in users" do
            it "should deny access" do
                get :index
                response.should redirect_to(signin_path)
                flash[:notice].should =~ /sign in/i
            end
        end

        describe "for signed-in-users" do

            before(:each) do
                @user = test_sign_in(Factory(:user))
                second = Factory(:user, :email => "another@example.com")
                third  = Factory(:user, :email => "another@example.net")

                @users = [@user, second, third]

                30.times do
                    @users << Factory(:user, :email => Factory.next(:email))
                end


            end

            it "should be successful" do
                get :index
                response.should be_success
            end

            it "should have the right title" do
                get :index
                response.should have_selector('title', :content => "All users")
            end

            it "should have an element for each user" do
                get :index
                @users[0..2].each do |user|
                #User.paginate(:page => 1).each do |user|
                    response.should have_selector('li', :content => user.name)
                end
            end

            it "should paginate users" do
                get :index
                response.should have_selector('div.pagination')
                response.should have_selector('span.disabled', :content => "Previous")
                #response.should have_selector('a', :href => "/users?page=2",
                #                                   :content => "2")
                #response.should have_selector('a', :href => "/users?page=2",
                #                                   :content => "Next")
            end
=begin
            it "should have delete links for admins" do
                @user.toggle!(:admin)
                other_user = User.all.second
                get :index
                response.should have_selector('a', :href => user_path(other_user),
                                                   :content => "delete")
            end

            it "should not have delete links for non-admins" do
                other_user = User.all.second
                get :index
                response.should_not have_selector('a', :href => user_path(other_user),
                                                       :content => "delete")
            end
=end
        end
    end

    describe "GET 'show'" do

        before(:each) do
          # used to be just Factory.build(:user)
          @user = Factory(:user)
        end

        it "should be successful" do
          get :show, :id => @user.id
          response.should be_success
        end

        it "should find the right user" do
          get :show, :id => @user.id

          # assigns(:user) returns the 
          # value of the instance variable @user
          assigns(:user).should == @user
        end

        it "should have the right title" do
          get :show, :id => @user.id
          response.should have_selector('title', :content => @user.name)
        end

        it "should have the user's name" do
          get :show, :id => @user.id
          response.should have_selector('h1', :content => @user.name)
        end

        it "should have a profile image" do
          get :show, :id => @user.id
          response.should have_selector('h1>img', :class => "gravatar")
        end
    end

    describe "GET 'new'" do

        it "should be successful" do
          get :new
          response.should be_success
        end

        it "should have the right title" do
          get :new
          response.should have_selector('title', :content => "Sign Up")
        end
    end

    describe "POST 'create'" do

        describe "failure" do

            before(:each) do
                @attr = { :name => "", :email => "", :password => "",
                      :password_confirmation => "" }
            end

            it "should not create a user" do
                lambda do
                    post :create, :user => @attr
                end.should_not change(User, :count)
            end

            it "should have the right title" do
                post :create, :user => @attr
                response.should have_selector('title', :content => "Sign up")
            end

            it "should render the 'new' page" do
                post :create, :user => @attr
                response.should render_template('new')
            end
        end

        describe "success" do

            before(:each) do
                @attr = { :name => "New User", :email => "user@example.com",
                      :password => "foobar", :password_confirmation => "foobar" }
            end

            it "should create a user" do
                lambda do
                    post :create, :user => @attr
                end.should change(User, :count).by(1)
            end

            it "should redirect to the user show page" do
                post :create, :user => @attr
                response.should redirect_to(user_path(assigns(:user)))
            end

            it "should have a welcome message" do
                post :create, :user => @attr
                flash[:success].should =~ /welcome to the sample app/i
            end

            it "should sign the user in" do
                post :create, :user => @attr
                controller.should be_signed_in
            end

        end
    end

    describe "GET 'edit'" do

        before(:each) do
            @user = Factory(:user)
            test_sign_in(@user)
        end

        it "should be successful" do
            get :edit, :id => @user
            response.should be_success
        end

        it "should have the right title" do
            get :edit, :id => @user
            response.should have_selector('title', :content => "Edit user")
        end

        it "should have a link to change the Gravatar" do
            get :edit, :id => @user
            gravatar_url = "http://gravatar.com/emails"
            response.should have_selector('a', :href => 'http://gravatar.com/emails',
                                             :content => "change")
        end
    end



    describe "PUT 'update'" do

        before(:each) do
            @user = Factory(:user)
            test_sign_in(@user)
        end

        describe "failure" do

            before(:each) do
                @attr = { :email => "", :name => "", :password => "",
                          :password_confirmation => "" }
            end

            it "should render the 'edit' page" do
                put :update, :id => @user, :user => @attr
                response.should render_template('edit')
            end

            it "should have the right title" do
                put :update, :id => @user, :user => @attr
                response.should have_selector('title', :content => "Edit user")
            end
        end

        describe "success" do

            before(:each) do
                @attr = { :name => "New Name", :email => "user@example.org",
                          :password => "barbaz", :password_confirmation => "barbaz" }
            end

            it "should change the user's attributes" do
                put :update, :id => @user, :user => @attr
                @user.reload
                @user.name.should  == @attr[:name]
                @user.email.should == @attr[:email]
                #@user.encrypted_password.should == assigns(:user).encrypted_password
            end

            it "should redirect to the user show page" do
                put :update, :id => @user, :user => @attr
                response.should redirect_to(user_path(@user))
            end

            it "should have a flash message" do
                put :update, :id => @user, :user => @attr
                flash[:success].should =~ /updated/
            end
        end
    end

    describe "authentication of edit/update actions" do

        before(:each) do
            @user = Factory(:user)
        end

        describe "for non-signed-in users" do

            it "should deny access to 'edit'" do
                get :edit, :id => @user
                response.should redirect_to(signin_path)
                #flash[:notice].should =~ /sign in/i
            end

            it "should deny access to 'update'" do
                put :update, :id => @user, :user => {}
                response.should redirect_to(signin_path)
            end
        end

        describe "for signed-in users" do

            before(:each) do
                wrong_user = Factory(:user, :email => "user@example.net")
                test_sign_in(wrong_user)
            end

            it "should require matching users for 'edit'" do
                get :edit, :id => @user
                response.should redirect_to(root_path)
            end

            it "should require matching users for 'update'" do
                put :update, :id => @user, :user => {}
                response.should redirect_to(root_path)
            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-06-17T15:14:00+00:00Added an answer on June 17, 2026 at 3:14 pm

    Put the sequence inside the define block?

    FactoryGirl.define do
    
      sequence :email { |n| "person-#{n}@example.com" }
    
      factory :user do
        name "Pavan Katepalli"
        password "foobar"
        password_confirmation "foobar"
        email { FactoryGirl.generate(:email) }
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error when I run the program. Object reference not set
I keep getting this error when I call 'tomcat:run'. The plugin 'org.apache.maven.plugins:maven-tomcat-plugin' does not
I keep getting this error when trying to run a Rspec test as part
I keep getting this error when I run my web app (asp.net mvc) in
I keep getting this error when I try to run my TypeScript app: Should
I keep getting this error trying to run the debugger: Program received signal EXC_BAD_ACCESS,
I keep getting this error when I compile and run my Java program using
I'm trying to run a very simple integration test and keep getting this error:
I'm trying to run the code below and I keep getting this error back:
i keep getting this error for an array of errors that i have set

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.