Rails3、Cucumber、Capybara、文件上传 =>内容主体错误(EOFError)?
我很难进行简单的文件上传测试。我在 ruby 1.9.2 上使用 Rails 3.0.0 以及 Cucumber 和 Capybara。
查看:
<%= 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
当我尝试运行测试时,我收到:
(::) 失败的步骤 (::) 内容主体错误(EOFError) <内部:前奏>:10:在“同步”中
我感谢任何帮助或见解。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,这是机架测试的一个问题,并且在更多人采用 Rails3 和 Ruby 1.9.x 之前,对于大多数人来说这可能不会成为问题。
将rack-test升级到当前主分支解决了这个问题。
我不确定机架测试何时会在 gem 中包含这些更改。
参见:
groups.google.com/group/cukes/browse_thread/thread/5028306893c2c54a
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
我没有答案,但正在同一环境中解决同样的问题 - cukes、capybara、rails 3、1.9.2.... 如果我弄清楚了这一点会让你知道。您是否想过在 Cucumber google 群组或 Rails google 群组上发帖?如果你不这样做,一旦我整理好自己的行为并且无法弄清楚,我就会发布到其中之一。
另外,似乎webrat有attach_file()的方法,因此当我生成没有水豚的黄瓜时,它在web_steps.rb中有一个推论方法,但是在我添加水豚并重新生成黄瓜后它就消失了......
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....