7

I have implemented a JQuery-file-upload in my Rails4 app. File upload works when I manually test it from the browser, but my test for it fails.

Below is my spec for the JQuery-file-upload: require '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

I'm using RSpec 2, Capybara 2 and Poltergeist for this feature spec.

3 Answers 3

1

I am also using JQuery-file-upload with RSpec and Capybara. I am using the capybara-webkit driver, but this should work with selenium as well.

See the example method and usage found in this answer: https://stackoverflow.com/a/11203629/1084109

Sign up to request clarification or add additional context in comments.

Comments

0

Although you didn't say how / why your test fails: A common problem here is that the file-field is hidden, so capybara treats it as not there.

A solution that worked for me is to execute a script to show the file field, something along the lines of:

script = "$('input[type=file]').show();"
page.driver.browser.execute_script(script)

You might also need to hide your custom upload button / label. See also: Capybara, capybara-webkit and custom file upload form

Comments

0

This is a problem with poltergeist. Using another driver (for example selenium-webdriver) should resolve the issue. It appears that file upload events are not triggerred correctly with poltergeist.

(I have some jquery ajax file upload tests and the same problems: My file upload tests only do not work with poltergeist)

There is an closed issue where someone describes the same symptomps. But no clear solution.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.