File Processing with

I’m working on a project that allows users to upload files. Right now, I have tests written to handle uploading files, but not verifying those files. I know I want to eventually run this in a background process, and I’ve found plenty of RSpec gems for Sidekiq. I know how to parse and verify the files, but I want to approach this using TDD, as I’ve approached everything else in my project from a TDD perspective so far.

My main issue is trying to figure out how to start out with writing my tests. What would I write a test for first? I assume I’d continue writing an integration test - like “A User should not be able to upload an invalid file” - but past that, I’m lost. I’ve been trying to figure it out, but I haven’t been able to land on anything solid enough to me to start writing.

Does anyone have any thoughts? I’m not necessarily asking for someone to give me the exact answer, but maybe shove me in the right direction. I’ve tried Googling around for people using Sidekiq to see how they’ve approached writing their tests, but I’ve not had any luck so far.

The first test should usually be the happy path, not the invalid file path.

I would write a full capybara test that uploads the file and submits it to the server. After it is uploaded just make a basic assertion about the page such as the flash message saying that it was submitted properly. I typically recommend that you start off on these tests not using sidekiq and just processing it all directly inline. Once you have your spec written, then mode it to the background job.

Something as simple as this would be my typical starting point:

scenario 'user uploads a file' do
  visit new_file_upload_path
  fill_in 'name', with: 'my video'
  attach_file('upload', my_file_path)
  click_on 'Submit'
  expect(page).to have_content 'Your file has been uploaded and will be processed'
end

This is more of a smoke test but I personally find that after the first spec, they are all easier to write.

I should have clarified that I have a test much like the one you mentioned above. Basically exactly the same, except for a different message at the end. :stuck_out_tongue:

I figured writing the failing test (for a bad file upload) was the next step, but I didn’t fully grasp the step -after- that in the process - or, as you recommended, writing it all inline.

I should probably just take a stab at it and see where the tests take me.