Automated tests are how we keep a low defect rate without a QA department. This lesson covers why we test, the difference between unit and end-to-end tests, and...
...details, no chasing coverage 📄 Pyramid or Crab? Find a testing strategy that fits — the different test-suite shapes side by side 📄 Guidelines for Testing Rails Applications — the same discussion for...
Every test needs data. Instead of Rails' global fixtures we use factories that create only the records a test needs, which keeps tests isolated and predictable. Important
...lesson in teacher mode. Learning goals You can explain why we create test data with factories instead of fixtures: each test starts empty and creates only what it needs.
You can explain our approach to adopting a legacy app: end-to-end tests for the happy paths first, tests for everything you touch, improving whatever you work on...
...and regular time set aside for stability. You can explain why end-to-end tests, unlike unit tests, survive a refactoring — and why that makes them the first tests to...
Jasmine is a great tool to unit test your JavaScript components without writing an expensive end-to-end test for every little thing. Important Work on this lesson in builder...
...Any HTTP calls must be mocked. Learning goals You can explain what JavaScript unit tests cover that end-to-end tests shouldn't: a component's details and edge cases...
We use Selenium WebDriver with Capybara for end-to-end tests that need a real browser. Important Work on this lesson in advisor mode. Learning goals You can explain how...
...Capybara drives a browser, how its drivers differ (e.g. rack_test vs. Selenium), and when a feature spec needs a real browser. You can run a feature spec in a...
...you integrate geocoding, maps and a title-autocomplete API from JavaScript, and learn to test code that talks to external services. Important Work on this lesson in builder mode.
...from the browser to enrich your UI. You can design your JavaScript so a test can query its state through a small API, and drive it from a feature spec...
...use it, why it is useful even for single-language apps, and how to test it. Important Work on this lesson in builder mode. Learning goals You can explain what...
...the URL — and explain the trade-offs of each. You can explain a sensible testing strategy for localization: most tests in one language, explicit tests for switching and for non...
...differs from Rails defaults and the reasoning behind each difference. You can explain our testing strategy — end-to-end tests for every happy path plus many unit tests for edge...
...cases — and why we prefer it over the classic testing pyramid. You can recognize 37signals-specific pieces in tutorials and generated apps (e.g. Hotwire, Kamal, Solid Queue) and know to...
...data from external XML and JSON APIs in Ruby, and learn several techniques for testing code that talks to the network without making your test suite slow or flaky.
...the failure modes of an external API: errors, no results, ambiguous results. You can test code that talks to the network in several ways — real calls, stubs, request-level mocking...
...it solve the right problem, is the design sound, is it correct, is it tested, is it readable — and treat style last. You can navigate a change: understand the intent...
...Reviewing agent-generated code Code from an agent looks finished: consistent formatting, confident comments, tests that pass. That makes it harder to review, not easier. Treat it like code from...
You can give the agent a way to verify its own work (e.g. tests, a build, a screenshot) and explain why "looks done" is not done.
...and the agent work out the whole plan first — files involved, approach, edge cases, tests, what's out of scope — for example with the /agree-on-everything skill or by letting the...
...can structure specs with nested example groups, let, subject and before/after hooks, and share tests between similar classes with shared example groups. You can explain the trade-off between DRY...
...extracted into shared helpers instead of copied. You can explain what mocking is, use test doubles to take control of a collaborator, and name a case where a mocked test...
...and HTML views, and delivery methods that differ per environment. You can implement and test a mailer, including attachments, and preview mails during development. You can explain why development and...
...poster as a file attachment to the e-mail? Can you write a RSpec test for this? In the lesson Form Models we said that we don't like to...
...with its showtimes. This lesson covers Rails' nested attributes and how to build and test such forms. Important Work on this lesson in advisor mode. Learning goals You can explain...
...JavaScript as a reusable component that knows nothing about a particular model. You can test a nested form, including how to address repeated fields. You can lay out a nested...
...This lesson covers storing uploads as model attributes with CarrierWave, generating image versions, and testing uploads. Important Work on this lesson in advisor mode. Learning goals You can explain how...
...can keep an upload across a form redisplay after a validation error. You can test uploads: an end-to-end test for the happy path, unit tests for versions and...
...its effects on forms, views, lookups and login. You pick the cheapest kind of test that proves each behavior instead of writing an end-to-end test for everything.
Soft-deletable users As an exercise, make users soft-deletable in MovieDB. Write tests to ensure the following behaviors: Soft-deleted users are no longer visible on the users...
...data out of your database. This lesson covers Rails' built-in validations, how to test them, and how to show helpful error messages in your forms. Important
...can write a custom validation for a rule that spans several attributes. You can test a single validation in isolation, e.g. with Shoulda matchers. You can show validation errors next...
...which records a user sees, which transitions they may trigger — to the state. You test state-dependent behavior at the right level: end-to-end for the business process, unit...
...tests for transitions and validations, with factory traits for records in a given state. You know that multi-step "wizard" forms are a common use of state machines. Resources
...number of words, lines and paragraphs, and outputs the result. For example: $ ruby count_words.rb test.txt test.txt has 123 words test.txt has 13 lines test.txt has 4 paragraphs Hint
...tab, and inspect the live DOM. You can debug a failing end-to-end test by pausing it and inspecting the page and the server log. You review your own...
...and following the guidelines from the referred card above. If you are debugging rspec tests, you can use rspec -b to print the full stack trace. If you encounter problems...
...from the view back to the code that grants or denies access. You can test authorization without duplicating every feature spec for every role. You can discuss the structural choices...
...that says what a user may see and do, usable in controllers, views and tests 📄 assignable_values README — restrict an attribute to the values a user may pick, and validate...
...so extend them instead of rebuilding them. You can use accessible markup to make tests more robust, e.g. by matching elements by their accessible name or aria-label. Resources
...by role and accessible name in feature specs; also shows why accessible markup makes tests more robust 📄 Orca screen reader documentation — for the exercise on Linux Exercises Use MovieDB with...
...data and validate it against your own records before acting on it. You can test LLM-calling code without hitting the API in your test suite, using the techniques from...
...build pipeline bundles it. You can evaluate a library before adding it — maintenance, popularity, tests, dependencies, size — and prefer boring technology over the newest option. You can explain why the...
...keep maintaining the library if the original author stops doing so. Does it contain tests? The code quality of our libraries should generally be around the same level of our...