代码之家  ›  专栏  ›  技术社区  ›  astjohn

Rails3、Cucumber、Capybara、File Upload=>Bad Content Body(Eofiror)?

  •  8
  • astjohn  · 技术社区  · 14 年前

    我很难找到一个简单的文件上传测试。我在Ruby1.9.2上使用了Rails3.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
    

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

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

    我很感激你的帮助和洞察力。谢谢。

    2 回复  |  直到 13 年前
        2
  •  0
  •   David Kahn    14 年前