From 190ddb16eadf29586fdd2fd966e2f560feea188d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 30 Mar 2009 20:42:48 +0200 Subject: [PATCH] Ensure route_matcher works in RoutingExampleGroup [#26 status:resolved] --- lib/remarkable/controller/controller.rb | 9 +++++++ .../controller/macros/route_matcher.rb | 27 ++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/remarkable/controller/controller.rb b/lib/remarkable/controller/controller.rb index 978b7bd..4c77fb2 100644 --- a/lib/remarkable/controller/controller.rb +++ b/lib/remarkable/controller/controller.rb @@ -15,6 +15,15 @@ class ControllerExampleGroup private include Remarkable::Private end + + class RoutingExampleGroup + include Remarkable::Assertions + include Remarkable::Controller::Matchers + extend Remarkable::Controller::Macros + + private + include Remarkable::Private + end end end end diff --git a/lib/remarkable/controller/macros/route_matcher.rb b/lib/remarkable/controller/macros/route_matcher.rb index 1279090..1b7c64b 100644 --- a/lib/remarkable/controller/macros/route_matcher.rb +++ b/lib/remarkable/controller/macros/route_matcher.rb @@ -11,13 +11,10 @@ def initialize(method, path, options) def matches?(subject) @subject = subject - initialize_with_spec! + @options[:controller] ||= controller_name - unless @options[:controller] - @options[:controller] = @controller.class.name.gsub(/Controller$/, '').tableize - end @options[:controller] = @options[:controller].to_s - @options[:action] = @options[:action].to_s + @options[:action] = @options[:action].to_s @populated_path = @path.dup @options.each do |key, value| @@ -38,12 +35,18 @@ def description private - def initialize_with_spec! - # In Rspec 1.1.12 we can actually do: - # - # @controller = @subject - # - @controller = @spec.instance_eval { controller } + def controller_name + controller = if @spec.class.respond_to?(:controller_class) + @spec.class.controller_class + elsif @spec.class.respond_to?(:described_class) + @spec.class.described_class + end + + if controller.ancestors.include?(ActionController::Base) + controller.name.gsub(/Controller$/, '').tableize + else + raise ArgumentError, "I cannot guess the controller name in route_for. Please supply :controller as option" + end end def map_to_path? @@ -68,7 +71,7 @@ def expectation end def route(method, path, options) - Route.new(method, path, options) + Route.new(method, path, options).spec(self) end end end