Question

i have the following step definition:

When /^I upload it$/ do

end

which relates to a file upload. the visit method in capybara, from what i can tell is a GET only method .. and the only way to do a POST request is by implementation:

visit "/files/new"
within('#upload-form') do
  attach_file('File', @files_path+'/file.txt')
  click_button('Upload')
end

this doesnt seem a very strong test, as its dependant on the HTML and form tags within the files/new template.

is there a better way to handle this, or is this OK to do? i had in mind something like this:

post files_new_path { file: => 'a_file_on_the_system.txt' }

but then again cucumber tests are integration tests .. so which is the 'official' or best way to write tests at this level?

Was it helpful?

Solution

The Capybara codes mimic human actions. You can't expect human to "POST" but only "visit", "click_button" etc.

The syntax you mentioned would fit controller test better, but not integration test with Capybara.

The best style in integration test, in my opinion, is to think and act like human being but not machine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top