我很难让简单的文件上传测试工作.我在使用Cucumber和Capybara的
ruby 1.9.2上使用Rails 3.0.0.
视图:
<%= form_tag "/upload/create",:multipart => true do %> <label for="file">File to Upload:</label> <%= file_field_tag "file" %> <%= submit_tag "Upload" %> <% end %>
黄瓜步骤:
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
在我的控制器中,除了:
def create file = params[:file] end
Gemfile片段:
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
当我尝试运行测试时,我收到:
06004
我感谢任何帮助或见解.谢谢.
解决方法
事实证明这是机架测试的一个问题,在更多人采用Rails3和Ruby 1.9.x之前,它可能不会成为大多数问题.
将机架测试升级到current master branch修复了问题.
我不确定机架测试何时会在gem中包含这些更改.
也可以看看:
groups.google.com/group/cukes/browse_thread/thread/5028306893c2c54a