I've started learning how to test with Ministest. I have a side project that I'm using to run the tests.
I'm running a simple test where a user logs in, visits the projects index and attempts to create a new project.
I'm seeding via console with:
rake db:seed RAILS_ENV=test
There is a modal window at the index that asks the user to add "technologies" to his "skillset". I'm making the test close the modal so it can click on the Create Project button like so:
test "a logged in user can create a project" do
login_as users(:admin)
visit projects_url
click_on "Later" // close modal window
click_on "Create Project"
assert_equal new_project_path, page.current_path
end
However, I'm getting errors related to the modal window itself, because Technology.first, etc. is nil. As if the seed was not running and populating the DB.
Modal where Technology instances are used:
<div class="modal-body">
<p class="mr-3 mb-0" style="font-size: 1.4rem; text-align: center;">
<%= link_to (sanitize pick_tech_icon(Technology.first.name), tags: %w(i), attributes: %w(class style)) %>
<%= link_to (sanitize pick_tech_icon(Technology.second.name), tags: %w(i), attributes: %w(class style)) %>
<%= link_to (sanitize pick_tech_icon(Technology.third.name), tags: %w(i), attributes: %w(class style)) %>
<%= link_to (sanitize pick_tech_icon(Technology.fourth.name), tags: %w(i), attributes: %w(class style)) %>
<%= link_to (sanitize pick_tech_icon(Technology.fifth.name), tags: %w(i), attributes: %w(class style)) %>
</p>
</div>
Console error:
Error:
ProjectsTest#test_a_logged_in_user_can_create_a_project:
ActionView::Template::Error: undefined method `name' for nil:NilClass
app/views/shared/_add_skill_modal.html.erb:13
app/views/projects/index.html.erb:1
Why is my seed not working? Why does the test run OK if I use a Technology fixture to create Technology instances instead? I thought fixtures were not supposed to replace the DB data but rather serve as data to test against.
Aucun commentaire:
Enregistrer un commentaire