Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update feature_testing lesson for config change #340

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion module2/lessons/feature_testing_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,35 @@ RSpec.describe "songs index page", type: :feature do
end
```

## Routing Exceptions: Failing Loudly

As of Rails 7.1, testing configuration has changed a bit in a default Rails application. In the above example, we visit the `/songs` path. If we don't have that route created yet, we would expect that test to fail at that line to indicate to us that we need to create that route. However, with the new default Rails settings, that test wouldn't fail until it gets to the expectation below it to assert that the `song_1` title appears on the page.

Especially as you're learning about Rails, this configuration can cause a bit of confusion. How can we successfully visit a path that doesn't yet exist?! If you, like us, would rather see your test fail when Capybara tries to visit a route that doesn't exist, you can make a quick fix in your configuration!

In your `config/environments/test.rb` file, you should see this line at about line 32:
```
config.action_dispatch.show_exceptions = :rescuable
```

In order to see your route issue fail loudly and more clearly, change that line to:
```
config.action_dispatch.show_exceptions = :none
```

Now, if you run the above test and have not yet made that route, you should see this failure:
```
Failures:

1) songs index page can see all songs titles and play count
Failure/Error: visit "/songs"

ActionController::RoutingError:
No route matches [GET] "/songs"
```

You are not required to make this change, but we think this setting allows for better understanding of the error, and a clearer indication of the next step in the TDD flow.

## Practice

Write a test for the following user stories. Then, use TDD to implement the feature.
Expand Down Expand Up @@ -189,4 +218,4 @@ Then I am taken to the songs index
- What is Capybara?
- What are User Stories?

Completed code can be found on this branch [here](https://github.com/turingschool-examples/set-list-7/tree/feature-testing-complete).
Completed code can be found on this branch [here](https://github.com/turingschool-examples/set-list-7/tree/feature-testing-complete).