How to mock request object for rspec helper tests?
This isn't a complete answer to your question, but for the record, you can mock a request using ActionController::TestRequest.new()
. Something like:
describe ApplicationHelper do
it "should prepend subdomain to host" do
test_domain = 'xxxx:xxxx'
controller.request = ActionController::TestRequest.new(:host => test_domain)
helper.root_with_subdomain("test").should = "test.#{test_domain}"
end
end
You have to prepend the helper method with 'helper':
describe ApplicationHelper do
it "should prepend subdomain to host" do
helper.root_with_subdomain("test").should = "test.xxxx:xxxx"
end
end
Additionally to test behavior for different request options, you can access the request object throught the controller:
describe ApplicationHelper do
it "should prepend subdomain to host" do
controller.request.host = 'www.domain.com'
helper.root_with_subdomain("test").should = "test.xxxx:xxxx"
end
end
I had a similar problem, i found this solution to work:
before(:each) do
helper.request.host = "yourhostandorport"
end