How do i set a request.referrer inside my RSpec?
问题 I am trying to avoid using my session[:referred_by] , and would like to use the request.referrer . However, my RSpec tests fail because the TestRequest does not store a request.referrer So I have to do the following in order for Rspec tests to work. Is there a way to make it better: referrer = request.referrer ? request.referrer : '/' redirect_to referrer, :alert => error_message 回答1: Mock it: specify 'foo' do controller.request.should_receive(:referer).and_return('http://example.com') # get