1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/dispatch
Darren Cheng 6052fa9288 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.
2019-02-05 20:25:39 -08:00
..
request Enable Style/RedundantBegin cop to avoid newly adding redundant begin block 2018-12-21 06:12:42 +09:00
routing Support testing of non-ActionDispatch-routed apps. 2019-02-05 20:25:39 -08:00
session Respect ENV variables when finding DBs etc for the test suite 2019-02-06 01:20:06 +10:30
system_testing Add require "selenium/webdriver" to all using DrivenBySeleniumWith* classes 2019-01-30 17:15:44 +09:00
callbacks_test.rb Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
content_disposition_test.rb Encode Content-Disposition filenames on send_data and send_file 2018-09-13 21:38:46 +09:00
content_security_policy_test.rb Use request object for context if there's no controller 2018-10-22 17:16:52 +01:00
cookies_test.rb Cookie doesn't expire anymore unless a flag is set: 2019-02-04 14:25:17 +01:00
debug_exceptions_test.rb Loosen check of error cause file 2019-01-26 10:13:47 +09:00
debug_locks_test.rb Fix can't modify frozen String error in DebugLocks 2017-08-28 21:48:05 +09:00
exception_wrapper_test.rb Use backtrace cleaner to clean up backtrace for verbose query logs 2018-08-14 09:15:28 +10:00
executor_test.rb Replace assert ! with assert_not 2018-04-19 08:11:33 -04:00
header_test.rb Remove Rubocop's comments from Rails code base 2018-07-26 23:37:31 +03:00
host_authorization_test.rb Cleanup the whitelisting references after #33145 2019-02-03 10:58:10 +02:00
live_response_test.rb Changed webserver to web server. 2019-01-22 21:11:03 +05:30
mapper_test.rb Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
middleware_stack_test.rb Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
mime_type_test.rb Enable Style/RedundantBegin cop to avoid newly adding redundant begin block 2018-12-21 06:12:42 +09:00
mount_test.rb Define word boundary for unanchored path regexp 2019-02-05 07:54:51 +02:00
prefix_generation_test.rb Enable Performance/UnfreezeString cop 2018-09-23 08:56:55 +09:00
rack_cache_test.rb Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
reloader_test.rb Replace assert ! with assert_not 2018-04-19 08:11:33 -04:00
request_id_test.rb Allow @ in X-Request-Id header 2018-01-29 19:35:39 -05:00
request_test.rb Remove deprecated #acronym_regex method from Inflections 2019-01-17 16:08:33 -05:00
response_test.rb Module#{define_method,alias_method,undef_method,remove_method} become public since Ruby 2.5 2018-12-21 01:39:18 +09:00
routing_assertions_test.rb Make sure assert_recognizes can still find routes mounted after engines 2018-02-09 13:51:20 -05:00
routing_test.rb Remove secret_token rack env and cookie upgrade code 2019-01-17 16:08:34 -05:00
runner_test.rb Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
show_exceptions_test.rb Use env instead of headers on those tests 2018-11-26 15:21:11 -05:00
ssl_test.rb Check exclude before flagging cookies as secure in ActionDispatch::SSL (#32262) 2018-03-15 17:29:21 -04:00
static_test.rb Enable Performance/UnfreezeString cop 2018-09-23 08:56:55 +09:00
test_request_test.rb Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
test_response_test.rb Remove deprecated methods in ActionDispatch::TestResponse 2019-01-17 16:08:31 -05:00
uploaded_file_test.rb Add implicit to path conversion to uploaded file (#28676) 2018-07-22 10:00:40 +02:00
url_generation_test.rb Revert "Merge pull request #33970 from rails/eager-url-helpers" 2018-10-03 16:15:47 -05:00