Prefer using existing fixtures over creating new records in tests. For example, use leaves(:welcome_page) instead of books(:handbook).press Page.new(body: "..."), title: "...".
Use _path helpers instead of _url helpers in controller/integration tests unless you need to test across different hosts or explicitly need the full URL.
Preferred:
get book_slug_path(books(:handbook))Avoid:
get book_slug_url(books(:handbook))Use assert_in_body and assert_not_in_body to check if text is present or absent in the response body without DOM manipulation.
Preferred:
assert_in_body "Expected content"
assert_not_in_body "Unexpected content"Avoid:
assert_includes response.body, "Expected content"
assert_not_includes response.body, "Unexpected content"When using respond_to with default rendering, omit the { render } block as it's implied.
Preferred:
def show
respond_to do |format|
format.html
format.md
end
endAvoid:
def show
respond_to do |format|
format.html { render }
format.md { render }
end
end