Sha256: 69526b0ca1b64265d1b3ce83568e1b0ce03f23067590bce37e5c11f1d9c8d075

Contents?: true

Size: 1.02 KB

Versions: 24

Compression:

Stored size: 1.02 KB

Contents

module Spec
  module Rails
    module Matchers
      
      class Route
        def initialize(url)
          uri = URI.parse(url)
          @request = ActionController::TestRequest.new
          @request.env["HTTPS"] = uri.scheme == "https" ? "on" : nil
          @request.host = uri.host
          @request.request_uri = uri.path.empty? ? "/" : uri.path
        end
        
        def matches?(options)
          @options = options
          begin
            ActionController::Routing::Routes.recognize(@request) && @options == @request.symbolized_path_parameters
          rescue # recognize raises an error
            false
          end
        end
        
        def failure_message
          "expected #{@request.request_uri} to be recognized as #{@options.inspect}"
        end
        
        def negative_failure_message
          "expected #{@request.request_uri} to not be recognized as #{@options.inspect}"
        end
      end
      
      def recognize_request(url)
        Route.new(url)
      end
      
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-multi-site-extension-1.0.3 spec/matchers/route_matcher.rb
trusty-multi-site-extension-1.0.2 spec/matchers/route_matcher.rb
trusty-multi-site-extension-1.0.1 spec/matchers/route_matcher.rb
trusty-multi-site-extension-1.0.0 spec/matchers/route_matcher.rb