-2

我正在尝试学习 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
4

3 回答 3

4

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

bundle exec rake db:test:prepare
于 2013-04-29T14:43:58.550 回答
1

bundle exec rake db:test:clone

于 2013-04-29T14:51:55.900 回答
1

我也是 Rails 新手,遇到了一个非常相似的问题(在不同的项目上工作,但引用 Hartl 时出错)。在我的脑海中仔细考虑并使用谷歌搜索之后,我相信我找到了整体问题和解决方案。

不过,谁能解释一下 gems 中对 rails3tutorial 的引用以及如何删除它?

当我们开始 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 不同)。我很确定“常规 gemset”是错误的术语,但我仍处于初学者阶段,所以我向所有知道正确术语的人道歉。我希望这会有所帮助!

于 2014-01-07T23:32:37.597 回答