Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Test http redirect rules using Test::Unit
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib Allow overriding of the domain on a per test basis
test Allow overriding of the domain on a per test basis
.gitignore Writing Gemspecs isn't hard lets do it properly.
Gemfile.lock Remove the tests from the gem and get the date right
LICENSE.txt Update Readme and license
Rakefile Wrap some basic integration tests around the whole thing.
http_redirect_test.gemspec Release v1.0.2 (I really need overriding)


Version 1.0

Version 1 has drastically altered the syntax and strucutre of this gem, and is NOT backwards compatible with the old 0.1.3 release. You can now no longer use Ruby 1.8 with this gem.

If you absolutely must have the old version you can check out the v0.1.3 tag. However please be aware that this branch is over 4 years old and as such you should really upgrade your url tests to work with the latest version.

This library is released under the LGPL v2.1 a copy is included in the LICENSE.txt file


Makes sure your apache set up is working as you expect it to and check for regressions by running a suite of tests against it just as you would for any web application.


simply subclass HTTPRedirectTest in your tests and set the domain that you want to test

require 'http_redirect_test'

class ExampleComTest < HTTPRedirectTest
  set_domain ""

  def test_not_redirect
    should_not_redirect '/ok' # => Asserts 200 OK

  def test_should_redirect_non_permanantly
    should_redirect '/redirect', to: '/ok' # => Asserts 300, 301, 302, 303

  def should_redirect_permanently
    should_redirect '/redirect_permanant', to: '/ok', permanent: true # => Must be a 301 MOVED PERMANENTLY

  def test_should_not_be_found
    should_not_be_found '/not_found' # => Asserts 404 NOT FOUND

  def test_should_be_gone
    should_be_gone '/gone' # => Asserts 410 GONE

  def test_custom_header
    should_have_header('/custom_header', 'X-One-Million-Years', with_value: 'Dungeon')

class AllRedirectsArePermanent < HTTPRedirectTest
  set_domain ""
  treat_all_redirects_as_permanent # => All redirects in this test must 301

  def test_should_redirect
    should_redirect '/redirect_permanant', to: '/ok'

  def test_explicit_non_permanent_check_should_override
    should_redirect '/redirect', to: '/ok', permanent: false # => Must be redirect but not a 301

  def test_overriding_domain_names_temporarily
    override_domain_with '' do
      should_not_redirect '/'


Pull requests and patches are welcome. Please make sure you add tests as appropriate.

There are two sets of tests to check - the unit tests can be run using the default rake task - just run rake or rake test.

The integration suite fires up a small internal Sinatra app to provide some test endpoints and runs the integration tests against that. It will send a kill -9 to this app when it finishes. We don't want zombie processes hanging around ;)

You can run the integration tests using rake integration_test


Inspired by a blog post by Patrick Reagan of Viget Labs.

Something went wrong with that request. Please try again.