簡體   English   中英

Rspec失敗-NameError:未初始化的常量Faker

[英]Rspec Failure - NameError: uninitialized constant Faker

我正面臨以下失敗:在Rspec中-使用Mongodb作為數據庫並設計用於用戶管理。 無法理解是什么問題。

用這個命令

捆綁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

spec / factories / users.rb

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

寶石文件

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"

NameError:未初始化的常量Faker

您的應用程序中有ffaker gem,它是faker 重構版本 因此,您需要使用FFaker而不是Faker

email { FFaker::Internet.email }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM