Skip to content

Adding routes using with_routing has no effect and results in ActionController::RoutingError #817

Closed
@TylerRick

Description

@TylerRick

I expected all of these examples to pass:

require 'spec_helper'

class SubclassController < ApplicationController
  def test
    render text: 'ok'
  end
end

describe SubclassController do
  def skip_routing
    with_routing do |map|
      map.draw do
        # I've tried both of these versions:
        match ':controller/:action'
        #get 'subclass/:action' => 'subclass'
      end
      yield
    end
  end

  # This passes.
  specify do
    skip_routing do
      expect(get: '/subclass/test').to route_to("subclass#test")
    end
  end

  # This fails. Why?
  specify do
    skip_routing do
      get :test
      response.body.should == 'ok'
    end
  end
end

But one of them fails:

  1) SubclassController 
     Failure/Error: get :test
     ActionController::RoutingError:
       No route matches {:controller=>"subclass", :action=>"test"}
     # ./spec/controllers/application_controller_spec.skip_routing.rb:33:in `block (3 levels) in <top (required)>'
     # ./spec/controllers/application_controller_spec.skip_routing.rb:19:in `block in skip_routing'
     # ./spec/controllers/application_controller_spec.skip_routing.rb:13:in `skip_routing'
     # ./spec/controllers/application_controller_spec.skip_routing.rb:32:in `block (2 levels) in <top (required)>'
     # -e:1:in `<main>'

How can I get it to recognize the route added with with_routing?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions