views:

104

answers:

2

I'm having a hard time getting a simple file upload test working. I'm using Rails 3.0.0 on ruby 1.9.2 with Cucumber and Capybara.

View:

<%= form_tag "/upload/create", :multipart => true do %>
  <label for="file">File to Upload:</label>
  <%= file_field_tag "file" %>
  <%= submit_tag "Upload" %>
<% end %>

Cucumber Step:

When /^I upload the basic file$/ do  
  visit path_to("upload")
  path = File.join(::Rails.root, "somefile") 
  attach_file("file", path)
  click_button("Upload")
end

In my controller, i have commented out everything except for:

def create
  file = params[:file]
end

Gemfile snippet:

group :development, :test do
  # testing with specs
  gem "ZenTest", ">= 4.3.3"
  gem "autotest"
  gem "rspec-rails", ">= 2.0.0.beta.19", :git => "git://github.com/rspec/rspec-rails.git"
  gem "rspec", :git => "git://github.com/rspec/rspec.git"
  gem "rspec-core", :git => "git://github.com/rspec/rspec-core.git"
  gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
  gem "rspec-mocks", :git => "git://github.com/rspec/rspec-mocks.git"
  # cucumber stuff
  gem 'capybara'
  gem 'database_cleaner'
  gem 'cucumber-rails'
  gem 'cucumber'
  gem 'spork'
  gem 'launchy'    # So you can do Then show me the page
  gem 'escape_utils' # needed to fix Cucumber - http://crimpycode.brennonbortz.com/?p=42
end

When I try to run the test, I receive:

(::) failed steps (::)
bad content body (EOFError)
<internal:prelude>:10:in `synchronize'

I appreciate any help or insight. Thanks.

A: 

I don't have an answer but working on the same problem in the same environ - cukes, capybara, rails 3, 1.9.2.... if I figure this out will let you know. Have you thought of posting on the cucumber google group or the Rails google group? If you don't once I get my act together and cant figure out will post to one of these.

Also, it seems that webrat has the method for attach_file() and thus when I generated cucumber without capybara it had a corollary method in web_steps.rb, but after I added capybara and regenerated cucumber it was gone....

David Kahn
Thanks for helping me out David. I haven't had the time yet to try to fall back on webrat yet and so I'm not sure where the problem is originating. So far I have posted on Capybara's home on git, but have yet to receive a response.
astjohn
A: 

This turned out to be an issue with rack-test and it probably won't be a problem for most until more people adopt Rails3 and Ruby 1.9.x.

Upgrading rack-test to the current master branch fixed the problem. I'm not sure when rack-test will include these changes in the gem.

See also: groups.google.com/group/cukes/browse_thread/thread/5028306893c2c54a

astjohn

related questions