Search code examples
rubyruby-on-rails-4ruby-on-rails-5rspec-rails

How do I include image path in my spec file?


I have an error when I'm including an image in *_spec.rb file in Ruby on Rails 6.0, I'm using rspec gem. I'm absolutly begginer in this framework, I believe error is relationed to windows path. I've read many post in Stack Overflow but I can't resolve yet. Content of my file is:

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

I attach a screenshot with the error:

enter image description here


Solution

  • According to the doc

    1) some input element on the page should have a name, id, or label_text matching "Main image"

    2) you should use relative (not absolute) path of the file, in your case /spec/images/avatar4.jpg