[英]Where to place Fixtures that are not associated with a model in Rails
I have to test a method which takes a Hash that is associated with some content I scrap from a website. 我必须测试一种采用散列的方法,该散列与从网站中删除的某些内容相关联。
Here is what I have tried to do in a file located in /test/fixtures/scrapped_sites.yml 这是我尝试在/test/fixtures/scrapped_sites.yml中的文件中执行的操作
web_sites:
product_images: <% { 'images' => [] } %>
Then in my test: 然后在我的测试中:
page = Page.new
page.my_method(web_sites(:product_images))
But I get: 但是我得到:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: scrapped_sites: DELETE FROM "scrapped_sites"
How/where should I create this Fixtures? 我应该如何/在何处创建此灯具?
EDIT: 编辑:
I have creating a file in test/data/scrapped_data.yml
that looks like this: 我已经在test/data/scrapped_data.yml
中创建了一个看起来像这样的文件:
web_sites:
scrapped: {'images' => []}
But when running trying to open that file I get: 但是在尝试打开该文件时,我得到:
Psych::SyntaxError: (##): did not find expected ',' or '}' while parsing a flow mapping at line 2 column 9
What am I doing wrong? 我究竟做错了什么?
Look at Yaml's nested mappings and Simple Inline Arrays 查看Yaml的嵌套映射和简单内联数组
Need to do something like (note indenting with two spaces in critical) 需要做类似的事情(注意缩进两个空格)
web_sites:
scrapped:
images: [img1.png, img2.png, img3.png]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.