Ruby Rails 4 个灯具需要 table
Ruby on Rails 4 fixtures require table
使用Rails时的Fixtures(我的环境Rails 4.2)
为什么当 运行 一个测试时,为什么当夹具存在但没有同名的 table 时出错?为什么 fixture 需要在 table 中有匹配的列?
例1:(table不存在)
- 创建夹具 joes.yml(乔 table 不存在)
- 运行耙子test:integration
- 您将得到的错误是:
ActiveRecord::StatementInvalid: SQLite3::SQLException: 没有这样的 table: joes: DELETE FROM "joes"
示例 2:(table 存在,但列不存在)
- 创建夹具 products.yml。这种情况 table 产品确实存在
- 添加一个 yml 块,其中包含产品中没有的列的名称 table。例如在 products.yml 文件
中添加条目 other: bla
- 运行耙子test:integration
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 您的测试数据库具有值,这样您就可以更方便地进行测试,而无需将大量数据放入其中,在设置测试时 运行。就这些了。
使用Rails时的Fixtures(我的环境Rails 4.2)
为什么当 运行 一个测试时,为什么当夹具存在但没有同名的 table 时出错?为什么 fixture 需要在 table 中有匹配的列?
例1:(table不存在)
- 创建夹具 joes.yml(乔 table 不存在)
- 运行耙子test:integration
- 您将得到的错误是:
ActiveRecord::StatementInvalid: SQLite3::SQLException: 没有这样的 table: joes: DELETE FROM "joes"
示例 2:(table 存在,但列不存在)
- 创建夹具 products.yml。这种情况 table 产品确实存在
- 添加一个 yml 块,其中包含产品中没有的列的名称 table。例如在 products.yml 文件 中添加条目 other: bla
- 运行耙子test:integration
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 您的测试数据库具有值,这样您就可以更方便地进行测试,而无需将大量数据放入其中,在设置测试时 运行。就这些了。