| Module | RackBox::Matchers |
| In: |
lib/rackbox/matchers.rb
|
Custom RSpec matchers
# File lib/rackbox/matchers.rb, line 6
6: def self.included base
7:
8: # this should really just be matcher(:foo){ ... }
9: # but there's a bit of other meta logic to deal with here
10: Object.send :remove_const, :RedirectTo if defined? RedirectTo
11: undef redirect_to if defined? redirect_to
12:
13: # the actual matcher logic
14: matcher(:redirect_to, base) do |response, url|
15: return false unless response['Location']
16: if url =~ /^\//
17: # looking for a relative match, eg. should redirect_to('/login')
18: relative_location = response['Location'].sub(/^https?:\/\//,'').sub(/^[^\/]*/,'')
19: # ^ there's probably a helper on Rack or CGI to do this
20: relative_location.downcase == url.downcase
21: else
22: response['Location'].downcase == url.downcase
23: end
24: end
25:
26: end