Assertions and Integration Tests
For the remainder of this chapter, we’re going to take a quick look at some of the aspects of the testing framework that we’ve not seen in detail. We’ll list all of the assertions available to you and make a quick pass through integration testing.
Assertions in Rails
Did you notice that functional tests for the photos
controller use a lot of assertions that are not part of Test::Unit, but seem to be specific to web
development (assert_redirected_to) and even specific
to Rails (assert_template)? Rails
provides these additional assertions. Table 7-2 shows all of the extra assertions
provided by Rails.
Table 7-2. Rails-supplied assertions
Assertion | Description |
|---|---|
| Asserts that two HTML strings are logically equivalent. |
assert_dom_not_equal | Asserts that two HTML strings are not logically equivalent. |
| Asserts that the provided options can generate the provided path. |
| Uses CSS selector syntax to assert contents of HTML or XML. |
| Asserts that the routing rules successfully parse the given URL path. |
| Asserts that the response is a redirect to the specified destination. |
| Asserts that the response was the given HTTP status code (or range of status codes). |
| Asserts that path (URL) and options match both ways. |
| Asserts that the request was rendered with the specified template file. |
| Asserts that the provided record is valid by active record ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access