views:

27

answers:

1

I've a view helper method which generates a url by looking at request.domain and request.port_string.

   module ApplicationHelper  
       def root_with_subdomain(subdomain)  
           subdomain += "." unless subdomain.empty?    
           [subdomain, request.domain, request.port_string].join  
       end  
   end  

I would like to test this method using rspec.

describe ApplicationHelper do
  it "should prepend subdomain to host" do
    root_with_subdomain("test").should = "test.xxxx:xxxx"
  end
end

But when I run this with rspec, I get this:

 Failure/Error: root_with_subdomain("test").should = "test.xxxx:xxxx"
 `undefined local variable or method `request' for #<RSpec::Core::ExampleGroup::Nested_3:0x98b668c>`

Can anyone please help me figure out what should I do to fix this? How can I mock the 'request' object for this example?

Are there any better ways to generate urls where subdomains are used?

Thanks in advance.

A: 

Check out railscasts screencast about subdomains in rails 3: http://railscasts.com/episodes/221-subdomains-in-rails-3

It should help you get the idea of how they work and maybe change the way you're trying to do those helpers yourself.

Eimantas