Class: RspecRailsRouting::Matchers::Routing::HaveNamedRoute
- Inherits:
-
Object
- Object
- RspecRailsRouting::Matchers::Routing::HaveNamedRoute
- Defined in:
- lib/rspec_rails_routing/matchers/have_named_route.rb
Instance Method Summary collapse
- #description ⇒ Object
- #example_call ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
- #format_args(args) ⇒ Object
-
#initialize(context, name, *args) ⇒ HaveNamedRoute
constructor
A new instance of HaveNamedRoute.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(context, name, *args) ⇒ HaveNamedRoute
Returns a new instance of HaveNamedRoute.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rspec_rails_routing/matchers/have_named_route.rb', line 9 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 |
Instance Method Details
#description ⇒ Object
20 21 22 |
# File 'lib/rspec_rails_routing/matchers/have_named_route.rb', line 20 def description "have a route named #{@name}, where e.g. #{example_call} == #{@expected_uri}" end |
#example_call ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/rspec_rails_routing/matchers/have_named_route.rb', line 41 def example_call call = "#{@name}_path" if ! @args.empty? call << "(#{format_args( @args )})" end call end |
#failure_message_for_should ⇒ Object
33 34 35 |
# File 'lib/rspec_rails_routing/matchers/have_named_route.rb', line 33 def "expected #{example_call} to equal #{@expected_uri}, but got #{@actual_uri}" end |
#failure_message_for_should_not ⇒ Object
37 38 39 |
# File 'lib/rspec_rails_routing/matchers/have_named_route.rb', line 37 def "expected #{example_call} to not equal #{@expected_uri}, but it did" end |
#format_args(args) ⇒ Object
50 51 52 53 54 |
# File 'lib/rspec_rails_routing/matchers/have_named_route.rb', line 50 def format_args( args ) @args.map do |a| a.is_a?( Hash ) ? a.inspect : a.to_s end.join( ', ' ) end |
#matches?(subject) ⇒ Boolean
24 25 26 27 28 29 30 31 |
# File 'lib/rspec_rails_routing/matchers/have_named_route.rb', line 24 def matches?(subject) begin @actual_uri = @context.send( "#{@name}_path", *@args ) @actual_uri == @expected_uri rescue NoMethodError false end end |