aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing/inspector_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch/routing/inspector_test.rb')
-rw-r--r--actionpack/test/dispatch/routing/inspector_test.rb50
1 files changed, 28 insertions, 22 deletions
diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb
index 127212b228..9150d5010b 100644
--- a/actionpack/test/dispatch/routing/inspector_test.rb
+++ b/actionpack/test/dispatch/routing/inspector_test.rb
@@ -3,6 +3,7 @@
require "abstract_unit"
require "rails/engine"
require "action_dispatch/routing/inspector"
+require "io/console/size"
class MountedRackApp
def self.call(env)
@@ -15,16 +16,10 @@ end
module ActionDispatch
module Routing
class RoutesInspectorTest < ActiveSupport::TestCase
- def setup
+ setup do
@set = ActionDispatch::Routing::RouteSet.new
end
- def draw(options = nil, formater = ActionDispatch::Routing::ConsoleFormatter::Sheet.new, &block)
- @set.draw(&block)
- inspector = ActionDispatch::Routing::RoutesInspector.new(@set.routes)
- inspector.format(formater, options).split("\n")
- end
-
def test_displaying_routes_for_engines
engine = Class.new(Rails::Engine) do
def self.inspect
@@ -305,7 +300,7 @@ module ActionDispatch
end
def test_routes_can_be_filtered
- output = draw("posts") do
+ output = draw(grep: "posts") do
resources :articles
resources :posts
end
@@ -322,6 +317,9 @@ module ActionDispatch
end
def test_routes_when_expanded
+ previous_console_winsize = IO.console.winsize
+ IO.console.winsize = [0, 23]
+
engine = Class.new(Rails::Engine) do
def self.inspect
"Blog::Engine"
@@ -331,50 +329,51 @@ module ActionDispatch
get "/cart", to: "cart#show"
end
- output = draw(nil, ActionDispatch::Routing::ConsoleFormatter::Expanded.new) do
+ output = draw(formatter: ActionDispatch::Routing::ConsoleFormatter::Expanded.new) do
get "/custom/assets", to: "custom_assets#show"
get "/custom/furnitures", to: "custom_furnitures#show"
mount engine => "/blog", :as => "blog"
end
- assert_equal ["--[ Route 1 ]------------------------------------------------------------",
+ assert_equal ["--[ Route 1 ]----------",
"Prefix | custom_assets",
"Verb | GET",
"URI | /custom/assets(.:format)",
"Controller#Action | custom_assets#show",
- "--[ Route 2 ]------------------------------------------------------------",
+ "--[ Route 2 ]----------",
"Prefix | custom_furnitures",
"Verb | GET",
"URI | /custom/furnitures(.:format)",
"Controller#Action | custom_furnitures#show",
- "--[ Route 3 ]------------------------------------------------------------",
+ "--[ Route 3 ]----------",
"Prefix | blog",
"Verb | ",
"URI | /blog",
"Controller#Action | Blog::Engine",
"",
"[ Routes for Blog::Engine ]",
- "--[ Route 1 ]------------------------------------------------------------",
+ "--[ Route 1 ]----------",
"Prefix | cart",
"Verb | GET",
"URI | /cart(.:format)",
"Controller#Action | cart#show"], output
+ ensure
+ IO.console.winsize = previous_console_winsize
end
-
def test_no_routes_matched_filter_when_expanded
- output = draw("rails/dummy", ActionDispatch::Routing::ConsoleFormatter::Expanded.new) do
+ output = draw(grep: "rails/dummy", formatter: ActionDispatch::Routing::ConsoleFormatter::Expanded.new) do
get "photos/:id" => "photos#show", :id => /[A-Z]\d{5}/
end
assert_equal [
- "No routes were found for this controller",
+ "No routes were found for this grep pattern.",
"For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html."
], output
end
def test_not_routes_when_expanded
- output = draw("rails/dummy", ActionDispatch::Routing::ConsoleFormatter::Expanded.new) {}
+ output = draw(grep: "rails/dummy", formatter: ActionDispatch::Routing::ConsoleFormatter::Expanded.new) {}
assert_equal [
"You don't have any routes defined!",
@@ -386,7 +385,7 @@ module ActionDispatch
end
def test_routes_can_be_filtered_with_namespaced_controllers
- output = draw("admin/posts") do
+ output = draw(grep: "admin/posts") do
resources :articles
namespace :admin do
resources :posts
@@ -434,24 +433,24 @@ module ActionDispatch
end
assert_equal [
- "No routes were found for this controller",
+ "No routes were found for this controller.",
"For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html."
], output
end
def test_no_routes_matched_filter
- output = draw("rails/dummy") do
+ output = draw(grep: "rails/dummy") do
get "photos/:id" => "photos#show", :id => /[A-Z]\d{5}/
end
assert_equal [
- "No routes were found for this controller",
+ "No routes were found for this grep pattern.",
"For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html."
], output
end
def test_no_routes_were_defined
- output = draw("Rails::DummyController") {}
+ output = draw(grep: "Rails::DummyController") {}
assert_equal [
"You don't have any routes defined!",
@@ -484,6 +483,13 @@ module ActionDispatch
"custom_assets GET /custom/assets(.:format) custom_assets#show",
], output
end
+
+ private
+ def draw(formatter: ActionDispatch::Routing::ConsoleFormatter::Sheet.new, **options, &block)
+ @set.draw(&block)
+ inspector = ActionDispatch::Routing::RoutesInspector.new(@set.routes)
+ inspector.format(formatter, options).split("\n")
+ end
end
end
end