2011-10-23 17 views
7

Vorrei che tutti i miei test di unità usassero www.test.host anziché il valore predefinito test.host.Rails testing host richiesta di default

Ho provato a impostare ENV['HTTP_HOST'] in config/environments/test.rb, ma non è stato possibile.

Il mio scopo è quello di evitare un reindirizzamento nel mio test di controllo, l'uscita di ispezionare l'oggetto response nel mio test è:

#<ActionController::TestResponse:0x000001059ed378, ..., @header={"Location"=>"http://www.test.host", ... , @status=301, @body=["<html><body>You are being <a href=\"http://www.test.host\">redirected</a>.</body></html>"], ... , "REQUEST_METHOD"=>"GET", "SERVER_NAME"=>"example.org", "SERVER_PORT"=>"80",... , "HTTP_HOST"=>"test.host", "REMOTE_ADDR"=>"0.0.0.0" ...>> 

se fa la differenza, sto usando Rails3 e RSPEC2

risposta

11

Lo fai impostando request.host nel test. Puoi farlo globalmente aggiungendo questo al tuo test_helper.rb (comunque in Rails 3.1, non sono sicuro delle versioni precedenti, ma penso che sia simile):

class ActionController::TestCase 
    setup do 
    request.host = "www.test.host" 
    end 
end 
Problemi correlati