Skip to content
  • Darren Cheng's avatar
    6052fa92
    Support testing of non-ActionDispatch-routed apps. · 6052fa92
    Darren Cheng authored
    The [Grape API framework](https://github.com/ruby-grape/grape) regularly
    writes tests like
    [spec/grape/api_spec.rb](https://github.com/ruby-grape/grape/blob/master/spec/grape/api_spec.rb).
    
    When attempting to write a test in a Rails environment similar to the
    following:
    ```
    describe Grape::Api, type: :request do
      let(:app) {
        Class.new(Grape::API) do
          get 'test' do
            { foo: 'bar' }
          end
        end
      }
    
      it '200s' do
        get 'test'
      end
    end
    ```
    
    The following exception is thrown:
    
    ```
    NoMethodError: undefined method `url_helpers' for #<Array:0x00007fb4e4bc4c88>
    --
    0: .../lib/action_dispatch/testing/integration.rb:330:in `block in create_session'
    1: .../lib/action_dispatch/testing/integration.rb:326:in `initialize'
    2: .../lib/action_dispatch/testing/integration.rb:326:in `new'
    3: .../lib/action_dispatch/testing/integration.rb:326:in `create_session'
    4: .../lib/action_dispatch/testing/integration.rb:316:in `integration_session'
    5: .../lib/action_dispatch/testing/integration.rb:348:in `block (2 levels) in <module:Runner>'
    ```
    
    This change explicitly ensures that `app.routes` is an
    `ActionDispatch::Routing::RouteSet` instance.
    6052fa92
    Support testing of non-ActionDispatch-routed apps.
    Darren Cheng authored
    The [Grape API framework](https://github.com/ruby-grape/grape) regularly
    writes tests like
    [spec/grape/api_spec.rb](https://github.com/ruby-grape/grape/blob/master/spec/grape/api_spec.rb).
    
    When attempting to write a test in a Rails environment similar to the
    following:
    ```
    describe Grape::Api, type: :request do
      let(:app) {
        Class.new(Grape::API) do
          get 'test' do
            { foo: 'bar' }
          end
        end
      }
    
      it '200s' do
        get 'test'
      end
    end
    ```
    
    The following exception is thrown:
    
    ```
    NoMethodError: undefined method `url_helpers' for #<Array:0x00007fb4e4bc4c88>
    --
    0: .../lib/action_dispatch/testing/integration.rb:330:in `block in create_session'
    1: .../lib/action_dispatch/testing/integration.rb:326:in `initialize'
    2: .../lib/action_dispatch/testing/integration.rb:326:in `new'
    3: .../lib/action_dispatch/testing/integration.rb:326:in `create_session'
    4: .../lib/action_dispatch/testing/integration.rb:316:in `integration_session'
    5: .../lib/action_dispatch/testing/integration.rb:348:in `block (2 levels) in <module:Runner>'
    ```
    
    This change explicitly ensures that `app.routes` is an
    `ActionDispatch::Routing::RouteSet` instance.
Loading