Rails: tabela de banco de dados antiga e inexistente causa erros nos testes
Estou tentando executar um teste de unidade "verdade", mac_test.rb no aplicativo Rails, do qual fui encarregado recentemente. Se parece com isso
require 'test_helper'
class MacTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
Eu corrirake db:test:prepare
e estou tentando executar o teste usandoruby -I test test/unit/mac_test.rb
.
No entanto, recebo a seguinte saída de erro abreviada:
Loaded suite test/unit/mac_test
Started
EEEEEEEEEEEEEEE
Finished in 0.377261 seconds.
1) Error:
test_datas(ActionController::IntegrationTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: vendors: DELETE FROM "vendors" WHERE 1=1
2) Error:
testjigs(ActionController::IntegrationTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: vendors: DELETE FROM "vendors" WHERE 1=1
3) Error:
test_datas(ActionController::TestCase):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: vendors: DELETE FROM "vendors" WHERE 1=1
<more errors here>
15 tests, 0 assertions, 0 failures, 15 errors
Todos os 15 erros são semelhantes aos três primeiros - eles reclamam de uma tabela de fornecedores ausentes. Aparentemente, o fornecedor existia - havia alguns arquivos restantes como vendor_helper e também havia ummap.resources :vendor
no arquivo routes.rb. Excluí os arquivos antigos do fornecedor e excluímos map.resources: vendor line.
Portanto, não há modelo, exibição, controlador, teste, tabela de banco de dados ou qualquer coisa que tenha nomeado fornecedor / fornecedores. Usando o TextMate para procurar "fornecedor" (sem diferenciação de maiúsculas e minúsculas) no projeto, houve apenas uma ocorrência de "fornecedor" que não estava em um comentário, um arquivo de log, o arquivo README ou o arquivo boot.rb e no Capfile. (O que eu acho que não deve afetar os testes?)
Eu tentei usarrake db:reset
para ver se havia alguma coisa estranha no banco de dados, mas ainda está explodind
Se eu tentar usarrake test:units --trace
, (apenas para obter o rastreio, não sei como obtê-lo com o teste individual) recebo a saída abreviada:
** Invoke test:units (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:units
/usr/local/bin/ruby -I"lib:test" "/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/auth_code_test.rb" "test/unit/cal_data_test.rb" "test/unit/calibration_test.rb" "test/unit/helpers/auth_codes_helper_test.rb" "test/unit/helpers/jn_macs_helper_test.rb" "test/unit/jn_mac_test.rb" "test/unit/log_entry_test.rb" "test/unit/mac_test.rb" "test/unit/option_test.rb" "test/unit/q_test_test.rb" "test/unit/serial_test.rb" "test/unit/source_test.rb" "test/unit/test_data_test.rb" "test/unit/testjig_test.rb"
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Finished in 1.06271 seconds.
1) Error:
test_datas(ActionController::IntegrationTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: vendors: DELETE FROM "vendors" WHERE 1=1
<more similar errors>
52 tests, 0 assertions, 0 failures, 52 errors
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby -I"lib:test" "/usr/loc...]
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:995:in `sh'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1010:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1010:in `sh'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1094:in `sh'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1029:in `ruby'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1094:in `ruby'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/testtask.rb:117:in `define'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1112:in `verbose'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/testtask.rb:102:in `define'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19
Estou sem saber como fazer isso não explodir. Alguém pode me ajudar a encontrar uma maneira de fazer com que o Rails perceba que não deve mais haver "fornecedores"?
Edit: Estou usando o Rails 2.3.2 e o ruby 1.8.7 (nível 066 de atualização de 2009-06-12) [i686-darwin9.7.0]