加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – NameError:未初始化的常量Faker ::

发布时间:2020-12-17 04:21:51 所属栏目:百科 来源:网络整理
导读:Before(:all) do puts "HELLO ALL :D"end 我的代码有问题: /spec/factories.rb require 'faker'FactoryGirl.define do factory :booking_error do booking_id { Faker::Number.number(3).to_i } error_type_cd BookingError.error_types.values.shuffle.fir
Before(:all) do 
    puts "HELLO ALL :D"
end

我的代码有问题:

/spec/factories.rb

require 'faker'
FactoryGirl.define do
    factory :booking_error do 
    booking_id       { Faker::Number.number(3).to_i }
    error_type_cd    BookingError.error_types.values.shuffle.first
    process_name     Enums::FlightEnum::PROCESSES.keys.shuffle.first
    description      "DESCRIPTION"
    old_value        "OLD_STRING"
    new_value        "NEW_STRING"
    end
end

/spec/models/booking_error_spec.rb

require 'spec_helper'
describe BookingError do
    before(:all) do
        @booking_error       = FactoryGirl.build(:booking_error)
        @booking_error_types = BookingError.error_types
    end

    it 'Validating BookingError save.' do
        @booking_error.save.should be_true
    end
end

的Gemfile

source 'https://rubygems.org'

gem 'rails','3.2.13'

gem 'mysql2','0.3.11'
gem 'devise','2.2.0.rc'
gem 'devise-encryptable','0.1.1'
gem 'unicorn','4.5.0'
gem 'kaminari','0.14.1'
gem 'memcache-client','1.8.5'
gem 'simple_enum','1.6.4'
gem 'resque','1.23.0',:require => "resque/server"
gem 'resque-logger','0.1.0'
gem 'resque-workers-lock'
gem 'whenever','0.8.1',:require => false
gem 'httparty','0.9.0'
gem 'newrelic_rpm','3.6.1.88'
gem 'cancan','1.6.8'
gem 'rolify','3.2.0'
gem 'json-schema','1.1.1'
gem 'faker','1.1.2'
gem 'ruby-enum','0.2.1'
gem 'mail','2.5.4'
gem 'daemons-rails'

group :develop,:test do
  gem 'capistrano','2.13.5'
  gem 'capistrano-unicorn','0.1.6',:require => false
  gem 'capistrano-resque','~> 0.1.0',:require => false
  gem 'rvm-capistrano','1.2.7'
  gem 'capistrano-ext'
  gem 'rspec-rails','2.12.0'
  gem 'debugger','1.5.0'
  gem 'thin','1.5.0'
  gem 'annotate','2.5.0'
  gem 'factory_girl_rails','4.1.0'
  gem 'yard','0.8.5.2'
end


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'therubyracer','0.10.2'
  gem 'coffee-rails','3.2.2'
  gem 'uglifier','1.3.0'
  gem 'twitter-bootstrap-rails','2.1.9'
  gem 'sass','3.2.4'
  gem 'jquery-ui-rails','3.0.0'
  gem 'less-rails','2.2.6'
end

gem 'jquery-rails','2.1.4'

当我跑:

$rspec spec/models/booking_error_spec.rb

我收到标题中的错误:

NameError: uninitialized constant Faker::Number

解决方法

Faker中您使用的版本中不存在数字(1.1.2).更新到1.2.0版本,它将工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读