System testing: Capybara
This course explains what a Rails system spec is and how Capybara drives one. It covers the type: :system tag and Capybara's DSL for visiting pages, filling forms and asserting on page content. It reads the system-spec support that rspec-rails already ships in this app. It compares the rack_test driver with Selenium's JavaScript-capable variants. It then studies the sign-up password checklist, an interaction only a JavaScript-capable spec can check. It also reviews what the app's request specs prove and which client-side layer they leave untested.
What you'll learn
- ✓What type: :system specs are and how they differ from request specs
- ✓Capybara's DSL for visiting pages, filling forms and asserting on page content
- ✓The system-spec support already built into rspec-rails
- ✓The rack_test driver and why it cannot run JavaScript
- ✓Selenium's JavaScript-capable drivers and choosing one with driven_by
- ✓Spotting client-side behavior that only a JavaScript-capable spec can check
What a system spec actually is
This app has dozens of request spec files under spec/requests/, with a few hundred examples between them. spec/requests/auth_spec.rb posts form params to auth_sign_up_path and checks expect(response).to redirect_to(new_auth_two_factor_setup_path). That proves the server accepted the signup and…
Read the full lesson free →Curriculum
7 lessonsWhat a system spec actually is
Explains what a system spec adds over request specs and introduces Capybara's DSL for navigation, forms and assertions.
rspec-rails already ships the plumbing, in this app's installed gem
Reads the system-spec support inside the installed rspec-rails gem and shows why a default system spec asks for selenium-webdriver.
rack_test: Capybara's fast default driver, without JavaScript
Describes rack_test, Capybara's pure-Ruby default driver, which works through Rack and cannot run JavaScript.
The JavaScript-capable drivers: Selenium's variants
Covers Selenium's four pre-registered drivers, the rspec-rails default of headless Chrome, and how to choose a driver.
A JavaScript-driven view in this app: the sign-up password checklist
Reads the sign-up page's password strength Stimulus controller and sketches a system spec that checks its class changes.
What this app's request specs already cover, and the layer above them
Reviews what the app's request specs prove on the server side and the client-side behavior they never reach.
Putting it together: the toolkit, the gap, and where coverage goes next
Summarizes the toolkit and the gap: the app has zero system specs and no JavaScript-capable driver gem.