Sha256: 6005bbe2dcc91368efd885d016b6bbb1e534915a2a89fd38b06f0021cc953038
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
require 'rspec/expectations' module RspecRailsRouting module Matchers module Routing 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 false end end def failure_message "expected #{example_call} to equal #{@expected_uri}, but got #{@actual_uri}" end def failure_message_when_negated "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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rspec-rails-routing-3.0.0 | lib/rspec_rails_routing/matchers/have_named_route.rb |