ActionDispatch::TestRequest extends ActionDispatch::Request that extends Rack::Request.
The method is defined as follows
def referer
@env['HTTP_REFERER']
end
alias referrer referer
As far as I remember, you can access the environment variable in the RSpec test by using request.env. It means, it should be possible to set something like
request.env['HTTP_REFERER'] = 'http://example.com'
Of course, it depends on the type of RSpec example group you are using.