System Test
Rails Generate System Test (rails g system_test
) is the generator for System Tests (...duh). System tests (sometimes also called acceptance tests) run in a browser and simuluate user interactions with your app. Typically these use Capybara under the hood.
A freshly generated system test will look like this —
require "application_system_test_case"
class UsersTest < ApplicationSystemTestCase
# test "visiting the index" do
# visit users_url
#
# assert_selector "h1", text: "Users"
# end
end
Note that if you're using RSpec
for your tests, you want to use the rspec:system
generator, not system_test
. This system test generator is for creating Test::Unit
system tests.
rails g system_test
rails g system_test
System Test Name
Generator Options
Runtime Options
❯ rails g system_test Usage: rails generate system_test NAME [options] Options: [--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated engines) [--skip-collision-check], [--no-skip-collision-check] # Skip collision check [--system-tests=NAME] # System tests to be invoked Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist
Description: Generates a new system test. Pass the name of the test, either CamelCased or under_scored, as an argument. This generator invokes the current system tool, which defaults to TestUnit. Example: `bin/rails generate system_test GeneralStories` creates a GeneralStories system test in test/system/general_stories_test.rb