问题描述
我很难进行简单的文件上传测试.我在带有 Cucumber 和 Capybara 的 ruby 1.9.2 上使用 Rails 3.0.0.
查看:
<%= form_tag "/upload/create", :multipart =>真的做%><label for="file">要上传的文件:</label><%= file_field_tag "文件" %><%= submit_tag "上传" %><%结束%>
黄瓜步:
当/^我上传基本文件$/时访问 path_to("上传")path = File.join(::Rails.root, "somefile")attach_file("文件", 路径)click_button("上传")结尾
在我的控制器中,我已经注释掉了所有内容,除了:
定义创建文件 = 参数 [:文件]结尾
Gemfile 片段:
group :development, :test do# 测试规格宝石ZenTest",>= 4.3.3"宝石自动测试"gem "rspec-rails", ">= 2.0.0.beta.19", :git =>git://github.com/rspec/rspec-rails.git"宝石rspec",:git =>git://github.com/rspec/rspec.git"宝石rspec-core",:git =>git://github.com/rspec/rspec-core.git"gem "rspec-expectations", :git =>git://github.com/rspec/rspec-expectations.git"宝石rspec-mocks",:git =>git://github.com/rspec/rspec-mocks.git"#黄瓜的东西宝石水豚"宝石'database_cleaner'宝石'黄瓜导轨'宝石黄瓜"宝石'spork'gem 'launchy' # 所以你可以做 然后给我看页面gem 'escape_utils' # 需要修复 Cucumber - http://crimpycode.brennonbortz.com/?p=42结尾
当我尝试运行测试时,我收到:
(::) 失败的步骤 (::)错误的内容正文 (EOFError)<internal:prelude>:10:in `synchronize'
感谢任何帮助或见解.谢谢.
这被证明是机架测试的一个问题,在更多人采用 Rails3 和 Ruby 1.9.x 之前,这对大多数人来说可能不会成为问题.
将 rack-test 升级到 当前 master 分支 解决了这个问题.我不确定 rack-test 何时会将这些更改包含在 gem 中.
另请参阅:groups.google.com/group/cukes/browse_thread/thread/5028306893c2c54a
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:
I appreciate any help or insight. Thanks.
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
这篇关于Rails3、Cucumber、Capybara、文件上传=>错误的内容正文(EOFError)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!