我已經在Rails4應用程序中實現了JQuery文件上傳。當我從瀏覽器手動測試文件時,文件上傳工作正常,但我的測試失敗。如何使用RSpec和Capybara測試JQuery文件上傳
下面是我對jQuery的文件上傳規格: 需要「spec_helper」
feature 'Evidences' do
context "as an assessor user" do
let!(:assessor) { User.make! :assessor }
let!(:assessment) { Assessment.make! }
background { sign_in assessor }
scenario "it uploads evidence", js: true do
evidences_count_before_upload = assessment.evidences.count
visit edit_assessment_path(assessment)
path = "#{Rails.root}/spec/fixtures/files/sample1.doc"
attach_file 'evidence_file_url', path
expect(assessment.evidences.count).to eq(evidences_count_before_upload + 1)
end
end
end
我使用的RSpec 2,水豚2和騷靈此功能規格。