2014-12-12 6 views
11

Ich versuche, ein einfaches Bündel exec rake db auszuführen: Samen für meine Datenbank in Rails 4. Wenn jedoch läuft es, erhalte ich die folgende Ausgabe:NameError: nicht initialisierte Konstante Faker; Ruby on Rails

********-C02MGBVJFD57:myapp ***********$ bundle exec rake db:seed 
Your Gemfile lists the gem factory_girl_rails (>= 0) more than once. 
You should probably keep only one of them. 
While it's not a problem now, it could cause errors if you change the version of just one of them later. 
rake aborted! 
NameError: uninitialized constant Faker 
/Users/**********/workspace/myapp/db/seeds.rb:16:in `block in <top (required)>' 
/Users/**********/workspace/myapp/db/seeds.rb:15:in `times' 
/Users/**********/workspace/myapp/db/seeds.rb:15:in `<top (required)>' 
/Users/**********/.rvm/gems/[email protected]/gems/railties-4.1.4/lib/rails/engine.rb:543:in `load_seed' 
/Users/**********/.rvm/gems/[email protected]/gems/activerecord-4.1.4/lib/active_record/tasks/database_tasks.rb:184:in `load_seed' 
/Users/**********/.rvm/gems/[email protected]/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>' 
Tasks: TOP => db:seed 
(See full trace by running task with --trace) 

Hier ist meine seeds.rb Datei:

User.create!(
    name:     "Example User", 
    email:     "[email protected]", 
    password:    "foobar", 
    password_confirmation: "foobar", 
    admin:     true 
) 

99.times do |n| 
    name  = Faker::Name.name 
    email = "example-#{n+1}@railstutorial.org" 
    password = "password" 
    User.create!(
    name:     name, 
    email:     email, 
    password:    password, 
    password_confirmation: password 
) 
end 

Linie 16:

name = Faker::Name.name 

Irgendwelche Ideen, warum ich diese Störung erhalte? Vielen Dank.

+0

Haben Sie den Faker Juwel? – ptd

+0

Ich habe den Faker Gem unter meiner gemfile in der Gruppe: test do – user1072337

+3

Hatten Sie 'Rake db: seed' in der Testumgebung? Vorausgesetzt, Sie führen es in der Entwicklung aus, müssen Sie es auch Ihrer Entwicklungsgruppe hinzufügen. – ptd

Antwort

26

konfrontiert Gerade ähnliches Problem - ich war

läuft
rails g model model_name 

und erhalte die Fehlermeldung:

uninitialized constant Faker (NameError) 

Problem zu darauf zurückzuführen war, dass ich Juwel test Gruppe hinzugefügt.

es in developmentundtest Gruppe platzieren das Problem gelöst:

group :development, :test do 
    # ... 
    gem 'faker' 
    # ... 
end 
2

ich das gleiche Problem konfrontiert, während rspec Schreiben und das Hinzufügen von require 'faker' in Spec-Datei es gelöst.

+0

in der einzelnen Tests spec Datei oder in der rails_helper.rb Datei? – BKSpurgeon