aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/testing/integration.rb
diff options
context:
space:
mode:
authorDarren Cheng <darren@thanx.com>2019-02-05 19:34:00 -0800
committerDarren Cheng <darren@thanx.com>2019-02-05 20:25:39 -0800
commit6052fa9288c97be008acaa7eaed279ca55465ed7 (patch)
treebed1db361178ca1ad1c6adc5d081141fff88845e /actionpack/lib/action_dispatch/testing/integration.rb
parentf16a397a3bbff55e83a5f9e8b17f90b542533e4e (diff)
downloadrails-6052fa9288c97be008acaa7eaed279ca55465ed7.tar.gz
rails-6052fa9288c97be008acaa7eaed279ca55465ed7.tar.bz2
rails-6052fa9288c97be008acaa7eaed279ca55465ed7.zip
Support testing of non-ActionDispatch-routed apps.
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.
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/integration.rb')
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index 45439a3bb1..10d85037ae 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -335,7 +335,7 @@ module ActionDispatch
klass = APP_SESSIONS[app] ||= Class.new(Integration::Session) {
# If the app is a Rails app, make url_helpers available on the session.
# This makes app.url_for and app.foo_path available in the console.
- if app.respond_to?(:routes)
+ if app.respond_to?(:routes) && app.routes.is_a?(ActionDispatch::Routing::RouteSet)
include app.routes.url_helpers
include app.routes.mounted_helpers
end