2012-01-25 20 views
16

नीचे फ़ाइल अपलोड करने के लिए मेरा परीक्षण कोड है।fixture_file_upload में {file} मौजूद नहीं है त्रुटि

describe "file process" do 
before(:each) do 
    # debugger 
    @file = fixture_file_upload('test.csv', 'text/csv') 
end 

it "should be able to upload file" do 
    post :upload_csv, :upload => @file 
    response.should be_success 
end 
end 

हालांकि, जब मैं rspec कल्पना चलाने के लिए, यह मुझे त्रुटि

Failure/Error: @file = fixture_file_upload('test.csv', 'text/csv') 
RuntimeError: 
    test.csv file does not exist 
# ./spec/controllers/quotation_controller_spec.rb:29:in `block (3 levels) in <top (required)>' 

नीचे उत्पादित मैं स्थानों में से बहुत googled है लेकिन मैं अभी भी बाहर क्या इसके पीछे कारण नहीं पा सके। कोई उपाय?

+7

में रखा जाना चाहिए SO [http://stackoverflow.com/questions/3966263/attachment-fu-testing-in-rails-3 ](http:// से एक समाधान मिला stackoverflow.com/questions/3966263/attachment-fu-testing-in-rails-3)। जाहिर है, मुझे इस लाइन के साथ fixture_file_upload को प्रतिस्थापित करना है '@file = रैक :: टेस्ट :: अपलोड किया गया File.new (Rails.root.join (' spec/fixtures/test.csv '),' text/csv ')' – hanchee

+0

fixture_file_upload रेल 3.1 के साथ काम नहीं कर रहा है? – hanchee

+1

हमने इसे 3.2 – plainjimbo

उत्तर

0

this सवाल पर सबसे मतदान जवाब के आधार पर, आप {Rails.root} के तहत फ़ाइल डाल करने के लिए/कल्पना/फिक्स्चर/

26

Fixture_file_upload मूल रूप से अभी भी काम करता है फ़ाइलों की है। आप बस अपनी spec_helper.rb फ़ाइल में यकीन है कि जुड़नार पथ बनाने की जरूरत है uncommented & सही ढंग से spec/fixtures पथ & करने के लिए सेट ActionDispath::TestProcess शामिल करने के लिए है:

RSpec.configure do |config| 
    config.include ActionDispatch::TestProcess 

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 
    config.fixture_path = "#{::Rails.root}/spec/fixtures" 

    ... 

और जहाँ आप अपने परीक्षण में फ़ाइल को निर्दिष्ट कर रहे हैं, पूर्व में होना करने के लिए सुनिश्चित करें कि आपके '/' की तरह निम्न उदाहरण के साथ फ़ाइल नाम:

describe "POST /subscriber_imports" do 
    let(:file) { { :file => fixture_file_upload('/files/data.csv', 'text/csv') } } 
    subject { post :create, :subscriber_import => file } 
    ... 
end 

फ़ाइल का निरपेक्ष पथ config.fixture_path में निर्दिष्ट आधार पथ के साथ साथ रिश्तेदार पथ में fixture_file_upload समारोह कॉल निर्दिष्ट नहीं है। तो, इस उदाहरण में, file.csv#{::Rails.root}/spec/fixtures/files/data.csv

+3

यह भी ध्यान दें कि 'ActionDispatch शामिल करें: : TestProcess'। यह विशेष रूप से मेरे लिए समस्या को हल करता है – FeifanZ

+0

'एक्शनडिस्चैच :: टेस्टप्रोसेस' शामिल है जो मेरे लिए भी तय है। अजीब हिस्सा यह है कि हमने अन्य rspec परीक्षणों में 'fixture_file_upload' जुर्माना का उपयोग किया था, लेकिन यह एक नए के लिए विफल रहा। हो सकता है कि यह नया नमूना मॉड्यूल में स्कॉप्ड किया गया हो। – nrowegt

संबंधित मुद्दे