title: How do I test my application's response to malformed URLs?
body: <p>In the development and testing environment, we don't really see any malformed URLs, but in the real world, applications are often accessed by poorly-written crawlers, people trying SQL injection attacks, etc. requesting malformed URLs from the application (unescaped punctuation, etc.).</p>
  
  <p>I found that my site being requested from a malformed URL was tickling a bug, so I went to fix the bug and write tests for it.  Here is an example of a test:</p>
  
  <pre><code>  scenario "with a garbage URL" do
      visit "/&lt;&lt;"
  
      # my actual expectation is irrelevant to this question
      expect(some_result).to have_happened
    end
  </code></pre>
  
  <p>The problem here is that <code>visit "/&lt;&lt;"</code> throws an exception <em>in the testing tool</em>, and my application never gets hit, because Capybara will refuse to visit a malformed URL.</p>
  
  <p>So, what is the best way to test whether my application is replying appropriately to malformed URLs, invalid query strings, etc. that the testing tool won't generate?</p>