使用Rails测试数据库错误

时间:2013-04-29 14:39:56

标签: ruby-on-rails ruby tdd

我正在尝试学习Rails,遇到一些我不明白的问题。我从Hartl的书开始,看到这个错误信息,它看起来与我为此做的事情有关。

现在我正在开展一个新项目,当我尝试在我的路线文件上运行测试时,我得到了这个。

1) Error:
test_that_/login_route_opens_the_login_page(CursomRoutesTest):
ActiveRecord::StatementInvalid: Could not find table 'statuses'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:472:in `table_structure'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in `columns'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:660:in `column_names'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:652:in `timestamp_column_names'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:585:in `block in table_rows'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:579:in `each'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:579:in `map'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:579:in `table_rows'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:494:in `block (3 levels) in create_fixtures'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:492:in `each'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:492:in `block (2 levels) in create_fixtures'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:491:in `block in create_fixtures'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:168:in `disable_referential_integrity'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:476:in `create_fixtures'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:895:in `load_fixtures'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activerecord-3.2.13/lib/active_record/fixtures.rb:849:in `setup_fixtures'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:418:in `_run__3689392786993953837__setup__3124079788890242138__callbacks'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/TomEllis/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:35:in `run'

1 tests, 0 assertions, 0 failures, 1 errors, 0 skips

3 个答案:

答案 0 :(得分:4)

您可能没有运行rake任务来准备测试数据库:

bundle exec rake db:test:prepare

答案 1 :(得分:1)

bundle exec rake db:test:clone

答案 2 :(得分:1)

我也是一个Rails新手,我遇到了一个非常类似的问题(处理不同的项目,但是引用错误引用Hartl)。在我的头脑中搜索并用谷歌搜索后,我相信我找到了整体问题和解决方案。

  

不过,有人可以解释一下rails3tutorial对gem的引用以及如何删除它吗?

当我们开始使用rails教程时,Hartl建议我们运行以下命令:

$ rvm use 1.9.3@rails3tutorial2ndEd --create --default
Using /Users/mhartl/.rvm/gems/ruby-1.9.3 with gemset rails3tutorial2ndEd

http://ruby.railstutorial.org/ruby-on-rails-tutorial-book?version=3.2#sec-install_rubygems

结果?

  

...每当我们打开一个新的终端窗口时,都会自动选择1.9.3@rails3tutorial2ndEd Ruby / gemset组合。

我通过运行来解决这个问题:

 rvm use 1.9.3-p484 --default

http://rvm.io/gemsets/using

这使得"定期" gemset我们的默认gemset(与我们的自定义Hart教程gemset相对)。我非常肯定"常规宝石"这是错误的术语,但我还处于初学阶段,所以我向所有知道正确用语的人道歉。我希望有所帮助!