8

我很难进行简单的文件上传测试。我在带有 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

宝石文件片段:

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

当我尝试运行测试时,我收到:

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

我感谢任何帮助或见解。谢谢。

4

2 回答 2

2

这被证明是机架测试的一个问题,在更多人采用 Rails3 和 Ruby 1.9.x 之前,这对大多数人来说可能不会成为问题。

将 rack-test 升级到当前的 master 分支解决了这个问题。我不确定 rack-test 何时会将这些更改包含在 gem 中。

另请参阅: groups.google.com/group/cukes/browse_thread/thread/5028306893c2c54a

于 2010-09-17T02:16:53.087 回答
0

我没有答案,但在同一个环境中解决同样的问题 - cukes、capybara、rails 3、1.9.2....如果我弄清楚了会让你知道的。你有没有想过在 cucumber google 组或 Rails google 组上发帖?如果你不这样做,一旦我把我的行为放在一起并且无法弄清楚将发布到其中之一。

此外,似乎 webrat 有 attach_file() 的方法,因此当我生成没有水豚的黄瓜时,它在 web_steps.rb 中有一个推论方法,但是在我添加水豚并重新生成黄瓜之后,它就消失了....

于 2010-09-15T00:00:30.093 回答