Ruby Rails 4 个灯具需要 table

Ruby on Rails 4 fixtures require table

使用Rails时的Fixtures(我的环境Rails 4.2)

为什么当 运行 一个测试时,为什么当夹具存在但没有同名的 table 时出错?为什么 fixture 需要在 table 中有匹配的列?

例1:(table不存在)

ActiveRecord::StatementInvalid: SQLite3::SQLException: 没有这样的 table: joes: DELETE FROM "joes"

示例 2:(table 存在,但列不存在)

ActiveRecord::Fixture::FixtureError: table "products" 没有名为 "other".

的列

我想我可以在我的测试中使用固定装置作为常用位置来引用,但不需要匹配我的数据库。

灯具就是你的数据,它们还需要一个地方去!

"Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model."

http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures

它们不是测试数据库的某种内存替代品,它们只是允许您 pre-populate 您的测试数据库具有值,这样您就可以更方便地进行测试,而无需将大量数据放入其中,在设置测试时 运行。就这些了。