{"record":{"id":"93bf70dc3cd7ba67","repo":"teamcapybara/capybara","slug":"capybara-app-host-should-be-set-to-a-url-http-w","errorCode":null,"errorMessage":"Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}.","messagePattern":"Capybara\\.app_host should be set to a url \\(http://www\\.example\\.com\\)\\. Attempted to set #(.+?)\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/capybara/session/config.rb","lineNumber":90,"sourceCode":"    remove_method :server_host\n\n    ##\n    #\n    # @return [String]    The IP address bound by default server\n    #\n    def server_host\n      @server_host || '127.0.0.1'\n    end\n\n    remove_method :server_errors=\n    def server_errors=(errors)\n      (@server_errors ||= []).replace(errors.dup)\n    end\n\n    remove_method :app_host=\n    def app_host=(url)\n      unless url.nil? || url.match?(URI_PARSER.make_regexp)\n        raise ArgumentError, \"Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}.\"\n      end\n\n      @app_host = url\n    end\n\n    remove_method :default_host=\n    def default_host=(url)\n      unless url.nil? || url.match?(URI_PARSER.make_regexp)\n        raise ArgumentError, \"Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}.\"\n      end\n\n      @default_host = url\n    end\n\n    remove_method :test_id=\n    ##\n    #\n    # Set an attribute to be optionally matched against the locator for builtin selector types.","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/session/config.rb#L72-L108","documentation":"Session::Config#app_host= validates the assigned value against a URI regexp: it must be a full URL with scheme (http://www.example.com) or nil. Assigning a bare host ('www.example.com'), host:port ('localhost:3000'), or a path raises ArgumentError at configuration time, naming the offending value. The parallel default_host= setter has the same rule.","triggerScenarios":"Capybara.app_host = 'www.example.com' (no scheme); Capybara.app_host = ENV['APP_HOST'] where the env var lacks http://; assigning 'localhost:9292' or '/app'.","commonSituations":"CI env vars configured without the scheme; copying hostnames from deployment configs or tickets; multi-environment suites where some env files store bare hosts.","solutions":["Include the scheme: Capybara.app_host = 'http://www.example.com'","Normalize env input before assigning: prefix http:// (or https://) when the scheme is missing","Set nil to clear the value; remember default_host= has the same requirement"],"exampleFix":"# before\nCapybara.app_host = ENV['APP_HOST'] # \"staging.example.com\" -> ArgumentError\n\n# after\nhost = ENV['APP_HOST']\nCapybara.app_host = host.start_with?('http') ? host : \"https://#{host}\"","handlingStrategy":"validation","validationCode":"def normalize_base_url(raw)\n  return nil if raw.nil? || raw.empty?\n  raw.match?(%r{\\Ahttps?://}) ? raw : \"http://#{raw}\"\nend\n\nCapybara.app_host = normalize_base_url(ENV['APP_HOST'])","typeGuard":"def valid_url?(str)\n  str.is_a?(String) && str.match?(URI::DEFAULT_PARSER.make_regexp)\nend","tryCatchPattern":"begin\n  Capybara.app_host = raw_host\nrescue ArgumentError\n  Capybara.app_host = \"http://#{raw_host}\"\nend","preventionTips":["Store full URLs (scheme + host) in env config, never bare hostnames","Validate app_host/default_host in a boot check before the suite runs"],"tags":["configuration","url","app-host","environment"],"backgroundTag":"invalid-url-configuration","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}