alias_method_chain stack level too deep in Rake test only

I have an odd error. I have the following module:

module ActionController
  module SslSupport

    def self.included(base)
      raise "#{base} does not define url_for" unless
      unless base.respond_to?(:url_for_without_ssl_supprt)
        base.send :include, InstanceMethods
        base.send :alias_method_chain, :url_for, :ssl_support

    module InstanceMethods

      def url_for_with_ssl_support(options)
        new_options = options.dup

        if options.kind_of?(Hash)
          new_options.merge!({ :only_path => false }) if request.ssl?
^ url_ssl?(new_options)
          if url_ssl?(new_options)
            new_options.merge!({ :protocol => 'https' })
            if ['development'].include?(ENV['RAILS_ENV'])
              new_options.merge!({ :port => 3001, :host => })



      def url_ssl?(options)
        case options
        when Hash
          protocol = options[:protocol] || 'http://'
          return options[:ssl] || protocol =~ /^https/
        when String
          return options =~ /^https/
          return self.class.method_defined?(:request) ? request.ssl? :



It is included in app/controllers/application.rb and in
ActionView::Base. If I run

ruby test/functional/people_controller_test.rb or ruby test/functional/
account_controller_test.rb, everything runs fine. If I run rake
test:functionals, however, I get a "stack level too deep" within
url_for within those two test classes.

Example output:

test_spec {The Account controller A guest (in general)} 001
[should be able to view the sign-up page](The Account controller
A guest (in general)):
ActionView::TemplateError: stack level too deep
    On line #8 of app/views/account/start.rhtml

    5: <h1>Create a free account in three steps:</h1>
    7: <ol>
    8: <li>a.&nbsp;<%= link_to 'Choose', :action => 'choose' %></li>
    9: <li>b.&nbsp;Create</li>
    10: <li>c.&nbsp;Customize</li>
    11: </ol>
    lib/action_controller/ssl_support.rb:36:in `url_ssl?'
    lib/action_controller/ssl_support.rb:28:in `url_for'
70:in `send'
70:in `url_for_without_ssl_support'
    lib/action_controller/ssl_support.rb:28:in `url_for'
136:in `link_to'

I figured that my self.included(base) would guard against this, but it
doesn't seem to work. Any thoughts?


I suppose I meant 'method_defined?' instead of 'respond_to?' but that
doesn't change the problem.