2016-05-22 52 views
0

我正面临这个失败:在Rspec中 - 用Mongodb作为数据库和用户管理的设计。无法理解这是什么问题。Rspec失败 - NameError:未初始化的常量Faker

与此命令

bundle exec rspec spec/models/user_spec.rb

 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

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 

规格/工厂/ users.rb的

FactoryGirl.define do 
    factory :user do 
    email { Faker::Internet.email } 
    password "12345678" 
    password_confirmation "12345678" 
    end 
end 

的Gemfile

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" 

回答

2

NameError: uninitialized constant Faker

您的应用程序ffaker宝石是重构版本faker。所以你需要使用FFaker而不是Faker

email { FFaker::Internet.email } 
+0

你知道吗,因为当这个Faker已经被弃用了。 –

相关问题