Dưới đây là mã thử nghiệm của tôi để tải lên tệp.fixture_file_upload có {file} không tồn tại lỗi
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
Tuy nhiên, khi tôi chạy rspec đặc tả, nó tạo ra cho tôi những lỗi dưới đây
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)>'
Tôi có googled rất nhiều nơi nhưng tôi vẫn không thể tìm ra lý do đằng sau đó là những gì. Bất kỳ ý tưởng?
Tìm thấy một giải pháp từ SO [http://stackoverflow.com/questions/3966263/attachment-fu-testing-in-rails-3](http:// stackoverflow.com/questions/3966263/attachment-fu-testing-in-rails-3). Rõ ràng, tôi phải thay thế fixture_file_upload bằng dòng này '@file = Rack :: Test :: UploadedFile.new (Rails.root.join ('spec/fixtures/test.csv'), 'text/csv')' – hanchee
fixture_file_upload không làm việc với Rails 3.1? – hanchee
Tôi bắt đầu thấy điều này sau khi chúng tôi nâng cấp lên 3.2 – plainjimbo