Using Feature Tests to Build a Feature

Learn about capybara API and how to write a test using capybara API.

When we last left the application, we allowed for the creation of new projects. Let’s follow up on that and add a sequence where we can see a page for an existing project and add a task to it. To give this a little bit of back-end logic to play with, let’s set up a situation where the tasks are ordered and then move one task above the other task.

Writing a test

This test has a few parts. Let’s take a second to plan the given/when/then:

  • Given: We’ll need one existing project and at least one existing task on that project so that we can test the ordering. We’ll probably want two tasks. That way, we can verify that the user interface is correct for the first, last, and middle parts of the list.
  • When/Then: The user fills out the form for the task, and we verify that the new task shows up.
  • When/Then: The user moves a task up, and we verify the order changes.

The fact that we have two distinct when/then pairs suggests this is probably two tests, but for ease of explanation, let’s keep it as one and see how it looks:

Get hands-on with 1400+ tech skills courses.