Dopo aver fatto qualche ricerca, ho scoperto che non esiste un modo per farlo. Le attività di test rake interromperanno sempre il database, anche quando viene fornita l'opzione TEST=
come suggerisce Bohdan.
Utilizzando l'opzione --trace
, questo può essere provato. Ecco l'output:
$ rake test:units TEST=test/unit/post_test.rb --trace
(in /Users/johnnyicon/Development/ror/test-app)
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:prepare
** Execute test:units
Leggendo il Ruby on Rails Guides for Testing, descrive quello che alcuni di questi compiti rake dire. Quello a cui prestare particolare attenzione è l'attività db:test:load
, che si vede sulla settima riga dalla parte inferiore dell'output come ** Execute db:test:load
. Le guide dicono che il seguente su questa operazione:
ricreare il database di prova dal schema.rb corrente
Quindi, anche se dovessi eseguire l'unità di test ad uno ad uno come suggerisce Bohdan, il il rake task ricreasse comunque il database. Non è la risposta che speravo, ma non è più un problema.
Il motivo per cui stavo chiedendo di iniziare era perché non avevo accesso a un altro database da utilizzare per il test, quindi stavo anche usando il mio database di sviluppo per testare. Ma da allora, sono stato in grado di ottenere un altro database dedicato per i test.
Grazie comunque Bohdan! Apprezzo l'aiuto!
Felice di sentirlo. Il database di test * deve * essere cancellato ogni volta che si eseguono i test, altrimenti i test saranno imprecisi. –