2012-05-02 4 views
27

मैं माइकल हार्टल्स रेल ट्यूटोरियल अध्याय 7 का अनुसरण कर रहा हूं। मैंने कारखाने की लड़की मणि स्थापित की है। मैं इस त्रुटि जब मैं चलाने के अपने परीक्षणफैक्टरी पंजीकृत नहीं है: उपयोगकर्ता

Failures: 

1) UsersController GET 'show' should be successful 
    Failure/Error: @user = FactoryGirl.create(:user) 
    ArgumentError: 
     Factory not registered: user 
    # ./spec/controllers/users_controller_spec.rb:10:in `block (3 levels) in <top (required)>' 

Finished in 0.66336 seconds 42 examples, 1 failure 

Failed examples: 

rspec ./spec/controllers/users_controller_spec.rb:14 # UsersController GET 'show' should be successful 

Gemfile बार आ रही है

group :test do 
    gem 'autotest', '4.4.6' 
    gem "autotest-growl", "~> 0.2.16" 
    gem "autotest-rails", "~> 4.1.2" 
    gem "rspec", "~> 2.9.0" 
    gem 'rspec-rails', '2.9.0' 
    gem 'webrat', '0.7.3' 
    gem "spork", '0.9.0' 
    gem 'annotate', '~> 2.4.1.beta' 
    gem "factory_girl", "~> 3.2.0" 
end 
# See https://github.com/sstephenson/execjs#readme for more supported runtimes 
gem 'therubyracer', :platform => 

मेरे user_controller_spec.rb

require 'spec_helper' 

describe UsersController do 

    render_views 

    describe "GET 'show'" do 
    before(:each) do 
    @user = FactoryGirl.create(:user) 
    end 

    it "should be successful" do 
     get :show, :id => @user 
     response.should be_success 
    end 
    end 

    describe "GET 'new'" do 
    it "should be successful" do 
     get :new 
     response.should be_success 
    end 

    it "should have the right title" do 
     get :new 
     response.should have_selector('title', :content => "Sign up") 
    end 
    end 
end 

है मेरे factories.rb है

FactoryGirl.create :user do |user| 
    user.name     "Mark Brown" 
    user.email     "[email protected]" 
    user.password    "foobar" 
    user.password_confirmation "foobar" 
end 

मैं

012 बदल गया
Factory(:name) 

FactoryGirl.create(:user) 
लाइन 10 पर

में करने के लिए अपने user_controller_spec.rb क्योंकि मैं एक deprication चेतावनी हो रही थी। मैंने सोचा कि यह ठीक करेगा लेकिन अब मैं बस मिल रहा हूँ।

Factory not registered: user 

क्या कोई मुझे बता सकता है कि क्या चल रहा है?

उत्तर

6

क्या होगा यदि आप पहले कारखाने को परिभाषित करते हैं, इसे नहीं बनाते? इस प्रयास करें:

FactoryGirl.define do 
    factory :user do 
    name     "Mark Brown" 
    email     "[email protected]" 
    password    "foobar" 
    password_confirmation "foobar" 
    end 
end 
+0

यह मेरे लिए काम किया। धन्यवाद! –

3

आप परीक्षण समूह

+0

मेरे लिए काम किया। मैंने गलती से 'factory_girl_rails' के बजाय मणि 'factory_girl' का उपयोग किया –

41

मैं जब मैं पहली बार है कि अध्याय में FactoryGirl द्वारा उपयोग किए गए त्रुटि थी तहत मणि 'factory_girl_rails' की आवश्यकता होगी और सभी मुझे क्या करने की जरूरत को पुनः आरंभ करने के लिए था यदि आप इसका उपयोग कर रहे हैं तो सर्वर और स्पार्क। उम्मीद है कि यह

+3

'स्पार्क' को रीसेट करने में मेरी मदद की, thx! – Martin

+3

वही, रेल सर्वर और गार्ड/स्पार्क दोनों को पुनरारंभ किया और फिर परीक्षण पास हो गए। यह एक कष्टप्रद है। – Raj

+0

समान समस्या और ज़ीउस उपयोगकर्ताओं के लिए ठीक करें। – Pistos

52

में मदद करता है मैंने इसे पहले ही तय कर दिया है।

समाधान मेरी जेमफाइल में gem 'factory_girl' से gem 'factory_girl_rails' को बदलना था।

+0

धन्यवाद। इसने मेरे लिए समस्या हल की। –

+0

यह मेरे लिए भी समस्या को ठीक करता है - धन्यवाद –

+0

शानदार। धन्यवाद! – creativetim

1

अपने Gemfile में आप के बजाय

gem "factory_girl", "~> 3.2.0" 
0

मैं अपने आईआरबी के रूप में जिज्ञासा उपयोग कर रहा था इस

gem "factory_girl_rails", "~> 4.0" 

से बदलना होगा। जब मैंने इसे अपने रत्नों से हटा दिया तो मैं फैक्ट्री लड़की को सही तरीके से काम करने में सक्षम था।

rails c -e test 

irb -> FactoryGirl.create(:user) 

शायद कोई यह बता सकता है कि इस प्रिये का उपयोग करके यह कैसे काम किया जाए।