How can I stub or mock the request.subdomains method in Rails?
integration-testing, mocking, ruby-on-rails, stubbing
Solution
In your functional test you should be able to do (using mocha):
@request.expects(:subdomains).returns(['www'])
Problem
I am trying to write some functional tests in my rails app, and in the application_controller.rb I have this: ``` before_filter :current_account def current_account @current_account ||= Account.find_by_subdomain!(request.subdomians.first) end ``` When running tests, `request.subdomains` doesn't contain the valid subdomains I'm looking for and makes it impossible to run any functional tests. Is it possible to stub the `current_account` method or mock the `request.subdomains` object?