title: How to mock request object for rspec helper tests?
body: <p>I've a view helper method which generates a url by looking at request.domain and request.port_string.</p>
  
  <pre><code>   module ApplicationHelper  
         def root_with_subdomain(subdomain)  
             subdomain += "." unless subdomain.empty?    
             [subdomain, request.domain, request.port_string].join  
         end  
     end  
  </code></pre>
  
  <p>I would like to test this method using rspec.</p>
  
  <pre><code>describe ApplicationHelper do
    it "should prepend subdomain to host" do
      root_with_subdomain("test").should = "test.xxxx:xxxx"
    end
  end
  </code></pre>
  
  <p>But when I run this with rspec, I get this:</p>
  
  <blockquote>
  <pre><code> Failure/Error: root_with_subdomain("test").should = "test.xxxx:xxxx"
   `undefined local variable or method `request' for #&lt;RSpec::Core::ExampleGroup::Nested_3:0x98b668c&gt;`
  </code></pre>
  </blockquote>
  
  <p>Can anyone please help me figure out what should I do to fix this?
  How can I mock the 'request' object for this example?</p>
  
  <p>Are there any better ways to generate urls where subdomains are used?</p>
  
  <p>Thanks in advance.</p>