title: Using rails' "post" in controller tests in rspec with scoping and protocol on routes
body: <p>I have a rails project that is running out of a subdirectory of the base url in production and I want it to act that way in dev so as to make dev and prod as close as possible. I have the routes file set up like so:</p>
  
  <pre><code>Foo::Application.routes.draw do
      def draw_routes
          root :to=&gt;'foo#home'
          resources :cats, :only=&gt;[:create] do
      end
      if Rails.env.production?
          scope :protocol=&gt;'http://' do
              draw_routes
          end
      else
          scope :path=&gt;"/foo", :protocol=&gt;'http://' do
              draw_routes
          end
      end
  end
  </code></pre>
  
  <p>My CatsController is like this:</p>
  
  <pre><code>class CatsController &lt; ApplicationController
      def create
          @cat = Cat.new(:name=&gt;"Bob")
          if @cat.save()
              redirect_to root
          end
      end
  end
  </code></pre>
  
  <p>I want to test my Create Cat Method, so I set up an rspec test in spec/controllers/cats_controller_spec.rb:</p>
  
  <pre><code>require 'spec_helper'
  describe CatsController do
      describe "calling create cat with good data" do
          it "should add a cat" do
              expect {post(:action=&gt;:create)}.to change(Cat, :count).by(1)
          end
      end 
  end
  </code></pre>
  
  <p>When I run my test, though, I get</p>
  
  <pre><code>Failure/Error: post :create
       ActionController::RoutingError:
         No route matches {:controller=&gt;"cats", :action=&gt;"create"}
       # ./spec/controllers/cats_controller_spec.rb:5:in `(root)'
  </code></pre>
  
  <p>Rake routes says my route is there! What is going on under the hood here, and why is this failing?</p>
  
  <pre><code>Rake Routes:
      cats POST   /foo/cats(.:format)            cats#create {:protocol=&gt;"http://"}
  </code></pre>