【问题标题】:Capybara spec failing when using attach_file with Dragonfly将 attach_file 与 Dragonfly 一起使用时 Capybara 规范失败
【发布时间】:2011-11-17 09:56:50
【问题描述】:

我正在为使用DragonFly gem 处理附件的表单页面编写规范,这是我的规范(相关部分)

fill_in "Subject", :with => 'My message'
fill_in "Title", :with => 'My image title'
fill_in "Content", :with => 'Message content'
attach_file 'Title image', Rails.root.join('spec', 'factories', 'test-image.png')
click_button "Create Message"
page.should have_content("Message was successfully created.")

但是它在click_button 步骤中失败并出现以下错误

Failure/Error: click_button "Create Message"
     ArgumentError:
       Dragonfly::TempObject must be initialized with a String, a Pathname, a File, a Tempfile, another TempObject, something that responds to .tempfile, or something that responds to .path

我追踪了这个错误,发现它是在this line 中提出的;我在那行之前放了一些调试指令,我发现obj是一个Array,其中包含图像的二进制数据,这是p obj.inspect返回的第一个数据

"[\"\\x89PNG\\r\\n\", \"\\u001A\\n\", \"\\u0000\\u0000\\u0000\\rIHDR\\u0000\\u0000\\u0003s\

我做错了什么?是我的错还是水豚和蜻蜓有些不兼容?

附:当我使用真正的浏览器访问应用程序时,它就像一个魅力。

【问题讨论】:

    标签: ruby ruby-on-rails-3 rspec capybara dragonfly-gem


    【解决方案1】:

    我使用的是旧版本的 Capybara,我已使用 bundle update capybara 将其更新到 1.1.2 版,问题就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-21
      相关资源
      最近更新 更多