首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rspec失败- NameError:未初始化常量Faker

Rspec失败- NameError:未初始化常量Faker
EN

Stack Overflow用户
提问于 2016-05-22 10:29:05
回答 1查看 1.2K关注 0票数 0

我面临着这样的失败:在Rspec中--使用Mongodb作为数据库,并为用户管理设计。不明白这是怎么回事。

用这个命令

包exec rspec规范/模型/user_spec.rb

代码语言:javascript
复制
      FFFF

Failures:

  1) User 
     Failure/Error: email { Faker::Internet.email }

     NameError:
       uninitialized constant Faker
     # ./spec/factories/users.rb:3:in `block (3 levels) in <top (required)>'
     # ./spec/models/user_spec.rb:19:in `block (2 levels) in <top (required)>'

  2) User 
     Failure/Error: email { Faker::Internet.email }

     NameError:
       uninitialized constant Faker
     # ./spec/factories/users.rb:3:in `block (3 levels) in <top (required)>'
     # ./spec/models/user_spec.rb:19:in `block (2 levels) in <top (required)>'

  3) User 
     Failure/Error: email { Faker::Internet.email }

     NameError:
       uninitialized constant Faker
     # ./spec/factories/users.rb:3:in `block (3 levels) in <top (required)>'
     # ./spec/models/user_spec.rb:19:in `block (2 levels) in <top (required)>'

  4) User 
     Failure/Error: email { Faker::Internet.email }

     NameError:
       uninitialized constant Faker
     # ./spec/factories/users.rb:3:in `block (3 levels) in <top (required)>'
     # ./spec/models/user_spec.rb:19:in `block (2 levels) in <top (required)>'

Finished in 0.00478 seconds (files took 2.1 seconds to load)
4 examples, 4 failures

Failed examples:

rspec ./spec/models/user_spec.rb:23 # User 
rspec ./spec/models/user_spec.rb:24 # User 
rspec ./spec/models/user_spec.rb:25 # User 
rspec ./spec/models/user_spec.rb:26 # User 

/spec/models/user_spec.rb

代码语言:javascript
复制
require 'spec_helper'


describe User do
    before { @user = FactoryGirl.build(:user)}

    subject { @user }

    it { should respond_to(:email) }
    it { should respond_to(:password) }
    it { should respond_to(:password_confirmation) }
    it { should be_valid }
end

spec/factories/users.rb

代码语言:javascript
复制
FactoryGirl.define do
  factory :user do
    email { Faker::Internet.email }
    password "12345678"
    password_confirmation "12345678"
  end
end

Gemfile

代码语言:javascript
复制
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
# gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'mongoid', '~> 5.1.0'

#Api gems
gem 'active_model_serializers'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem "factory_girl_rails"
  gem 'ffaker'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :test do
  gem "rspec-rails"
end

gem "devise"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-22 10:35:14

NameError:未初始化常量Faker

您的应用程序中有https://github.com/ffaker/ffaker gem,它是重构版 of https://github.com/stympy/faker。因此,您需要使用FFaker而不是Faker

代码语言:javascript
复制
email { FFaker::Internet.email }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37373161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档