{"record":{"id":"cfb7360d0aad606f","repo":"teamcapybara/capybara","slug":"rack-test-requires-a-rack-application-but-none-wa","errorCode":null,"errorMessage":"rack-test requires a rack application, but none was given","messagePattern":"rack-test requires a rack application, but none was given","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"critical","filePath":"lib/capybara/rack_test/driver.rb","lineNumber":17,"sourceCode":"# frozen_string_literal: true\n\nrequire 'rack/test'\nrequire 'rack/utils'\nrequire 'mini_mime'\nrequire 'nokogiri'\n\nclass Capybara::RackTest::Driver < Capybara::Driver::Base\n  DEFAULT_OPTIONS = {\n    respect_data_method: false,\n    follow_redirects: true,\n    redirect_limit: 5\n  }.freeze\n  attr_reader :app, :options\n\n  def initialize(app, **options)\n    raise ArgumentError, 'rack-test requires a rack application, but none was given' unless app\n\n    super()\n    @app = app\n    @options = DEFAULT_OPTIONS.merge(options)\n  end\n\n  def browser\n    @browser ||= Capybara::RackTest::Browser.new(self)\n  end\n\n  def follow_redirects?\n    @options[:follow_redirects]\n  end\n\n  def redirect_limit\n    @options[:redirect_limit]\n  end\n","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/rack_test/driver.rb#L1-L35","documentation":"Capybara::RackTest::Driver must be constructed with a Rack application; it drives your app in-process through Rack::Test and has no other target. The initializer raises ArgumentError when app is falsy. In practice this means Capybara.app (or the app block passed to a registered driver) is nil when the driver is instantiated on the first visit/current_session call.","triggerScenarios":"Capybara.default_driver = :rack_test with Capybara.app never set, then visit '/'; a custom registration dropping the block arg (Capybara.register_driver :my_driver { |_| Capybara::RackTest::Driver.new(nil) }); helper code like Capybara::RackTest::Driver.new(params[:app]) receiving nil.","commonSituations":"Standalone scripts or RSpec specs that skip rails_helper and never assign Capybara.app; testing a Sinatra/Rack app but assuming Capybara autodiscovers it; attempting to point rack_test at an external URL (unsupported - it needs the Rack object, not a host).","solutions":["Set the app before use: Capybara.app = MySinatraApp (or MyRailsApp, or a Rack builder) so the driver receives it.","In Rails, make sure specs load the environment (rails_helper) so Capybara.app picks up Rails.application automatically.","In custom driver registrations, pass the block argument through: Capybara.register_driver(:rack_test) { |app| Capybara::RackTest::Driver.new(app, **opts) }.","If you meant to hit an external site, switch to selenium/cuprite and set Capybara.app_host - rack_test cannot do this."],"exampleFix":"# before\nCapybara.default_driver = :rack_test\nvisit '/widgets' # Capybara.app is nil\n\n# after\nCapybara.app = MySinatraApp\nCapybara.default_driver = :rack_test\nvisit '/widgets'","handlingStrategy":"validation","validationCode":"raise 'Capybara.app must be set before using rack_test' if Capybara.app.nil?\nCapybara.default_driver = :rack_test","typeGuard":"def rack_app_configured?\n  !Capybara.app.nil?\nend","tryCatchPattern":null,"preventionTips":["Assign Capybara.app in a single bootstrap file loaded by every entry point (rails_helper, spec_helper, rake tasks).","Never drop the |app| block argument in Capybara.register_driver.","Remember rack_test only drives an in-process Rack app - external URLs need a browser driver plus app_host."],"tags":["ruby","capybara","rack-test","configuration"],"backgroundTag":"missing-required-configuration","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}