Sha256: 6b8b3ab114f75dca011ba3fafb75ad8bbdd8b562852be700593faed1486c128a

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require 'rspec/expectations'

module RspecRailsRouting
  module Matchers
    module Routing

      def have_named_route(name, *args)
        HaveNamedRoute.new(self, name, *args)
      end

      #class HaveNamedRoute
        #def initialize(context, name, *args)
          #@context = context
          #@name = name
          #@path = "#{name}_path"
          #@args = args
          #if ! args.last
            #raise ArgumentError, 'The last argument must be the expected uri'
          #end
          #@expected_uri = args.pop
        #end

        #def description
          #"have a route named #{@name}, where e.g. #{example_call} == #{@expected_uri}"
        #end

        #def matches?(subject)
          #begin
            #@actual_uri = @context.send( "#{@name}_path", *@args )
            #@actual_uri == @expected_uri
          #rescue NoMethodError => ex
            #false
          #end
        #end

        #def failure_message_for_should
          #"expected #{example_call} to equal #{@expected_uri}, but got #{@actual_uri}"
        #end

        #def failure_message_for_should_not
          #"expected #{example_call} to not equal #{@expected_uri}, but it did"
        #end

        #def example_call
          #call = "#{@name}_path"
          #if ! @args.empty?
            #call << "(#{format_args( @args )})"
          #end

          #call
        #end

        #def format_args( args )
          #@args.map do |a|
            #a.is_a?( Hash ) ? a.inspect : a.to_s
          #end.join( ', ' )
        #end

      #end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-rails-routing-3.0.0 lib/rspec_rails_routing/matchers/routing.rb
rspec-rails-routing-1.0.0 lib/rspec_rails_routing/matchers/routing.rb