Hi,
I’m trying to pass a feature test for uploading an image.
my form looks like this:
<%= form_for [:admin, @research_project] do |f| %>
<div>
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div>
<%= f.label :body %>
<%= f.text_area :body %>
</div>
<div>
<%= f.label :image %>
<%= f.file_field :image %>
</div>
<div>
<%= f.collection_check_boxes :research_theme_ids, ResearchTheme.all, :id, :title %>
</div>
<% if @research_project.new_record? %>
<%= f.submit "Add Research Project" %>
<% else %>
<%= f.submit "Update Research Project" %>
<% end %>
<% end %>
my feature test looks like this:
scenario 'Admin adds a research project' do
expect{
click_link "Add Research Project"
fill_in 'Title', with: @research_project.title
fill_in 'Body', with: @research_project.body
attach_file 'Image', "spec/support/uploads/monk_large.jpg"
click_button "Add Research Project"
}.to change(ResearchProject, :count).by(1)
expect(page).to have_content @research_project.title
expect(page).to have_content "you successfully added a new research project"
visit admin_research_project_path @research_project.id
expect(page).to have_css 'img', text: "monk_large.jpg"
end
when I run the test, I get this failure message, indication there is an img element but with no value for the src attribute:
1) Admin interacts with research projects Admin adds a research project
Failure/Error: expect(page).to have_css 'img', text: "monk_large.jpg"
Capybara::ExpectationNotMet:
expected to find css "img" with text "monk_large.jpg" but there were no matches. Also found "", which matched the selector but not all filters.
Can’t figure out why Capybara won’t attach the file. I put the test image in the folder: /spec/support/uploads
Any help is more then welcome
my repo is at: https://github.com/acandael/posplus-rails
greetings,
Anthony