Skip to content

Instantly share code, notes, and snippets.

@r38y
Created May 8, 2010 18:40
Show Gist options
  • Save r38y/394701 to your computer and use it in GitHub Desktop.
Save r38y/394701 to your computer and use it in GitHub Desktop.
How I test refraction in rspec
# Macros I use for testing refraction redirections. It can be used thusly:
# it_should_permanently_redirect('http://loseitorloseit.test/stats', 'http://loseitorloseit.test/people')
# it_should_temporarily_redirect('http://loseitorloseit.test/stats', 'http://loseitorloseit.test/people')
module RewriteMacro
module ExampleGroupMethods
def it_should_permanently_redirect(start_point, end_point)
it "should permanently redirect #{start_point} to #{end_point}" do
env = Rack::MockRequest.env_for(start_point, :method => 'get')
app = mock('app')
response = Refraction.new(app).call(env)
response[0].should == 301
response[1]['Location'].should == end_point
end
end
def it_should_temporarily_redirect(start_point, end_point)
it "should temporarily redirect #{start_point} to #{end_point}" do
env = Rack::MockRequest.env_for(start_point, :method => 'get')
app = mock('app')
response = Refraction.new(app).call(env)
response[0].should == 302
response[1]['Location'].should == end_point
end
end
end
def self.included(receiver)
receiver.extend ExampleGroupMethods
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment