I''ve read through the messages on this list, and have file upload specs working in my model and controller tests, using :file => ActionController::TestUploadedFile.new(filepath) But its not working in stories using webrat. I''ve tried fills_in "foo[file]", :with => filepath and fills_in "foo[file]", :with => ActionController::TestUploadedFile.new (filepath) both fail (0) when submit clicks_button ''Update'' oddly, in either case, a browser get opened, with something like file:///Users/jonathan/rails/myproject/tmp/webrat-1220026536.html which is blank suggestions? thx linoj
Jonathan Linowes wrote:> I''ve read through the messages on this list, and have file upload > specs working in my model and controller tests, using :file => > ActionController::TestUploadedFile.new(filepath) > > But its not working in stories using webrat. I''ve tried > > fills_in "foo[file]", :with => filepath > and > fills_in "foo[file]", :with => > ActionController::TestUploadedFile.new(filepath) > > both fail (0) when submit > clicks_button ''Update'' > > oddly, in either case, a browser get opened, with something like > file:///Users/jonathan/rails/myproject/tmp/webrat-1220026536.html > which is blank > > suggestions? > > thx > linoj > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersI haven''t been able to get the webrat uploading method (attaches_file) to work.... If you haven''t tried that method give it a shot, but I haven''t gotten it to work. To upload in stories I have done this: csv_file = ..... file_to_upload = ActionController::TestUploadedFile.new(csv_file.path, Mime::CSV) post my_path, "import_file" => file_to_upload In my story I didn''t have other fields in the form so I didn''t bother to investigate why webrat wasn''t working.. the clear disadvantage of the way I used is that I''m doing the post directly. -Ben
On Aug 29, 2008, at 12:52 PM, Ben Mabey wrote:> Jonathan Linowes wrote: >> I''ve read through the messages on this list, and have file upload >> specs working in my model and controller tests, using :file => >> ActionController::TestUploadedFile.new(filepath) >> >> But its not working in stories using webrat. I''ve tried >> >> fills_in "foo[file]", :with => filepath >> and >> fills_in "foo[file]", :with => >> ActionController::TestUploadedFile.new(filepath) >> >> both fail (0) when submit >> clicks_button ''Update'' >> >> oddly, in either case, a browser get opened, with something like >> file:///Users/jonathan/rails/myproject/tmp/webrat-1220026536.html >> which is blank >> >> suggestions? >> >> thx >> linoj >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > I haven''t been able to get the webrat uploading method (attaches_file) > to work.... If you haven''t tried that method give it a shot, but I > haven''t gotten it to work. To upload in stories I have done this: > > csv_file = ..... > file_to_upload = ActionController::TestUploadedFile.new(csv_file.path, > Mime::CSV) > post my_path, "import_file" => file_to_upload >i am trying that too, but at this point in my story i dont actually have the current record object to generate the form action path. How would i extract the :action = path from the <form> in the current response.body ?> > In my story I didn''t have other fields in the form so I didn''t > bother to > investigate why webrat wasn''t working.. the clear disadvantage of the > way I used is that I''m doing the post directly. > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
I too would suggest trying attaches_file. I use it in a few different stories I have, and it works fine for me. I don''t believe I''m doing anything nonstandard. Here''s the basics of what one of mine looks like (stripped out some fills_in''s, etc. to declutter the example): When "create a new hotel with photo from a ''$source''" do |source| visits new_location_path fills_in ''Name'', :with => ''Maui'' attaches_file ''location_photo'', File.join(Rails.root, ''stories'', ''fixtures'', ''BigPizza.jpg'') clicks_button ''Save'' end On Fri, Aug 29, 2008 at 9:52 AM, Ben Mabey <ben at benmabey.com> wrote:> Jonathan Linowes wrote: > > I''ve read through the messages on this list, and have file upload > > specs working in my model and controller tests, using :file => > > ActionController::TestUploadedFile.new(filepath) > > > > But its not working in stories using webrat. I''ve tried > > > > fills_in "foo[file]", :with => filepath > > and > > fills_in "foo[file]", :with => > > ActionController::TestUploadedFile.new(filepath) > > > > both fail (0) when submit > > clicks_button ''Update'' > > > > oddly, in either case, a browser get opened, with something like > > file:///Users/jonathan/rails/myproject/tmp/webrat-1220026536.html > > which is blank > > > > suggestions? > > > > thx > > linoj > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > I haven''t been able to get the webrat uploading method (attaches_file) > to work.... If you haven''t tried that method give it a shot, but I > haven''t gotten it to work. To upload in stories I have done this: > > csv_file = ..... > file_to_upload = ActionController::TestUploadedFile.new(csv_file.path, > Mime::CSV) > post my_path, "import_file" => file_to_upload > > > In my story I didn''t have other fields in the form so I didn''t bother to > investigate why webrat wasn''t working.. the clear disadvantage of the > way I used is that I''m doing the post directly. > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080829/dce9e8e6/attachment.html>
On Aug 29, 2008, at 1:19 PM, Jonathan Linowes wrote:> i am trying that too, but at this point in my story i dont actually > have the current record object to generate the form action path. > How would i extract the :action = path from the <form> in the > current response.body ?got it #assuming only one form on the page path = response.body.match(/action=\"([^"]+)\"/)[1] still, i dont like bypassing webrat though
When Webrat matches ''Exception caught'' on the get/post response body it tries to save the response body down as a html file and then invokes opening it in a browser (I believe the opening only works on OS X though I''ve never tested it in another os). This is a very useful feature unless you get a blank page :) I''ve had blank errors before which I''ve suspect was a bug but I never got around to looking at why they did not contain the response body.>oddly, in either case, a browser get opened, with something like >file:///Users/jonathan/rails/myproject/tmp/webrat-1220026536.html >which is blank-- Joseph Wilk http://www.joesniff.co.uk -- Posted via http://www.ruby-forum.com/.
On Aug 29, 2008, at 1:58 PM, Christopher Bailey wrote:> I too would suggest trying attaches_file. I use it in a few > different stories I have, and it works fine for me. I don''t > believe I''m doing anything nonstandard. Here''s the basics of whatyep, works for me :) thx -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080829/2b44600c/attachment.html>
This topic might be a little bit old, but since I run into this issue recently here''s the solution: Due to a lack of multipart form support for integration tests in Action Pack Webrat''s attach_file does not work with Rails 2.0.2. I posted a workaround on our blog: http://devblog.imedo.de/2009/9/2/file-uploads-with-webrat-in-ruby-on-rails-2-0-2. -- Posted via http://www.ruby-forum.com/.
In case there are other people trying to do the same thing, webrat''s implementation of attach_file has changed somewhat. See this URL for the current method to attach a file in your multipart form: http://gitrdoc.com/rdoc/brynary/webrat/273e8c541a82ddacf91f4f68ab6166c16ffdc9c5/classes/Webrat/Scope.html To summarize, syntax is attach_file (field_locator, path, content_type = nil) There is no need to call File.join or File.open, just specify the relative path. -- Posted via http://www.ruby-forum.com/.