prix-fixe

Expand History Expand History
Collapse History Collapse History

Add a failing system test

https://github.com/seanpdoyle/prix-fixe/projects/1#card-20484715

When I have a thought, I want to share a message, So that I can put me ideas into the world


This commit adds content to the scaffolded UserSharesAMessageTest block named "visiting the index".

Writing a test first, before the corresponding implementation is an integral part of Test-Driven Development.

Writing a System Test before other tests is an integral part of testing an application from the Outside In.

Our test is visually separated into blocks by newlines. It resembles a Four Phase Test.

  1. First, we’ll declare our test data in the test’s Setup Phase. For now the only test data that we’ll need is a String representing the new Note’s content attribute.

  2. Next, we declare the Exercise Phase. This phase will interact with the feature from a browser. Thinking in abstract terms, the exercise phase will:

  • visit the application’s root
  • click on a link to create a new Note
  • fill in a form field with the content of our Note
  • click on a button to submit the new Note

Each of these steps corresponds directly to a Capybara-provided method. The corresponding <form> fields’ elements’ label text is provided as an argument to each method call in this exercise phase.

  1. Next, we declare the Verify Phase. During this phase, our test will ensure that the behavior it expects aligns with the actual behavior. To do so, we assert that the content appears on the page by calling assert_text. In this case, the presence of the content on the page is a Good Enough :tm: indicator that the form submission was successful, and the Note was persisted well enough to be served to a user in a subsequent HTTP request.

  2. Finally, there is a Teardown Phase. The Teardown Phase is different from the others in that Rails’ system test harness handles the teardown steps on our behalf. For instance, tests that set .use_transactional_tests = true will configure the test to be a Transactional Test, and will be executed within a SQL Transaction. In practice, this means that records created within a test will only exist within the bounds of that test block. For now, our test suite’s teardown demands are limited to the database, but if future needs arose, they could be addressed with our test harness’ hook system.

When we execute the test, it fails:

Error:
UserSharesAMessageTest#test_visiting_the_index:
ActionController::RoutingError: No route matches [GET] "/"

This error informs us that our application does not know how to route or respond to GET / HTTP requests. Our next step will be resolve that error.