Question

I'm writing a spec for a form page which uses DragonFly gem to handle attachments, here is my spec (relevant part of it)

fill_in "Subject", :with => 'My message'
fill_in "Title", :with => 'My image title'
fill_in "Content", :with => 'Message content'
attach_file 'Title image', Rails.root.join('spec', 'factories', 'test-image.png')
click_button "Create Message"
page.should have_content("Message was successfully created.")

However it fails on the click_button step with the following error

Failure/Error: click_button "Create Message"
     ArgumentError:
       Dragonfly::TempObject must be initialized with a String, a Pathname, a File, a Tempfile, another TempObject, something that responds to .tempfile, or something that responds to .path

I tracked down this error and I've found that it's raised in this line; I've put some debug instruction before that line and I found out that obj is an Array which contains binary data of the image, here are the first data returned by p obj.inspect

"[\"\\x89PNG\\r\\n\", \"\\u001A\\n\", \"\\u0000\\u0000\\u0000\\rIHDR\\u0000\\u0000\\u0003s\

What I'm doing wrong? Is it my fault or there is some incompatibility with Capybara and Dragonfly?

P.S. When I access the application using a real browser it works like a charm.

Was it helpful?

Solution

I was using an old version of Capybara, I've updated it to version 1.1.2 with bundle update capybara and the problem is gone.

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