Sha256: 5c2bcedcc02793dfb2c8ce63c237afd55732ac4c9fa582123f9640bd4f011d94

Contents?: true

Size: 654 Bytes

Versions: 1

Compression:

Stored size: 654 Bytes

Contents

# frozen_string_literal: true

module RSpec::ResemblesJsonMatchers
  class ResemblesRouteMatcher
    ROUTE_REGEX = %r{\A/.*:}.freeze
    def self.can_match?(route_string)
      defined?(ActionDispatch) &&
        route_string.is_a?(String) &&
        route_string.start_with?("/") &&
        route_string.include?(":")
    end

    attr_reader :expected

    def initialize(expected_route)
      @expected = expected_route
    end

    def description
      "resemble route #{@expected.inspect}"
    end

    def matches?(actual)
      path = ActionDispatch::Journey::Path::Pattern.from_string(@expected)
      actual =~ path.to_regexp
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-resembles_json_matchers-0.9.1 lib/rspec/resembles_json_matchers/resembles_route_matcher.rb