ruby-on-rails – ArgumentError:序列未注册:电子邮件

ruby-on-rails – ArgumentError:序列未注册:电子邮件,第1张

概述我运行rspec时不断收到此错误:序列未注册:电子邮件. 但是,我确实在我的factories.rb文件中设置了它.有想法该怎么解决这个吗?该应用程序运行正常. Failures: 1) UsersController GET 'index' for signed-in-users should be successful Failure/Error: @users << Fact 我运行rspec时不断收到此错误:序列未注册:电子邮件.

但是,我确实在我的factorIEs.rb文件中设置了它.有想法该怎么解决这个吗?该应用程序运行正常.

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 seconds80 examples,4 failures

factorIEs.rb:

Factory.define :user do |user|    user.name "Pavan Katepalli"    user.email "[email protected]"    user.password "foobar"    user.password_confirmation "foobar"endFactory.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 => "[email protected]")                third  = Factory(:user,:email => "[email protected]")                @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',#                                   :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 @R_459_4034@s" do                other_user = User.all.second                get :index                response.should_not have_selector('a',: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 => "[email protected]",: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_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,:content => "Edit user")            end        end        describe "success" do            before(:each) do                @attr = { :name => "New name",:email => "[email protected]",:password => "barbaz",:password_confirmation => "barbaz" }            end            it "should change the user's attributes" do                put :update,: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,:user => @attr                response.should redirect_to(user_path(@user))            end            it "should have a flash message" do                put :update,: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,:user => {}                response.should redirect_to(signin_path)            end        end        describe "for signed-in users" do            before(:each) do                wrong_user = Factory(:user,:email => "[email protected]")                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,:user => {}                response.should redirect_to(root_path)            end        end    endend
解决方法 将序列放在define块中?

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) }  endend
总结

以上是内存溢出为你收集整理的ruby-on-rails – ArgumentError:序列未注册:电子邮件全部内容,希望文章能够帮你解决ruby-on-rails – ArgumentError:序列未注册:电子邮件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1293967.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存