【问题标题】:How do I include image path in my spec file?如何在我的规范文件中包含图像路径?
【发布时间】:2019-09-26 12:34:04
【问题描述】:

当我在 Ruby on Rails 6.0 的 *_spec.rb 文件中包含图像时出现错误,我正在使用 rspec gem。我在这个框架中绝对是初学者,我相信错误与 Windows 路径有关。我在 Stack Overflow 上读过很多帖子,但我还不能解决。我的文件内容是:

require "rails_helper.rb"
RSpec.feature "Admins pueden crear articulos" do
    scenario "con atributos validos" do
        visit "/"
        fill_in "Name", with: "Razones por las cuales aprender Ruby on Rails"
        fill_in "Content", with: "Es un gran lenguaje de programacion"
        attach_file "Main image",'D:/ProyectosPersonales/RubyProjects/blog/spec/images/avatar4.jpg'

        click_button "Guardar"
    end
end

我附上错误截图:

【问题讨论】:

    标签: ruby ruby-on-rails-4 ruby-on-rails-5 rspec-rails


    【解决方案1】:

    根据the doc

    1) 页面上的某些输入元素应具有与“主图像”匹配的名称、ID 或标签文本

    2)您应该使用文件的相对(不是绝对)路径,在您的情况下为/spec/images/avatar4.jpg

    【讨论】:

      【解决方案2】:

      查看File Fixtures,并将您的测试图像文件的副本添加到spec/fixtures/files/images/avatar4.jpg

      【讨论】:

        猜你喜欢
        • 2016-09-27
        • 1970-01-01
        • 2010-09-22
        • 1970-01-01
        • 2017-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多