在 Rails 中使用没有相应模型的装置

发布于 2024-08-21 10:10:01 字数 188 浏览 3 评论 0原文

我目前有一些大字符串,我想在测试日志抓取器时将其用作测试数据。将这些字符串放在 YAML 文件中会很好。

我很乐意在以简短明了的方式进行测试时参考它们,例如:

log_lines(:incorrect_string)

是否有使用固定装置来执行此操作,或者它们专门用于相应的模型?

I currently have some large strings that I would like use as test data when testing a log scraper. It would work well to have these strings in a YAML file.

I would love to refer to them while testing in a short and concise manner such as:

log_lines(:incorrect_string)

Is there anyway to do this using fixtures, or are they exclusively for use with a corresponding model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灵芸 2024-08-28 10:10:01

如果你的 yaml 看起来像这样:

:incorrect_string: blah

那么你就可以

logs = YAML::load_file('filename')
p logs[:incorrect_string]

欢呼了!

If your yaml looks like this:

:incorrect_string: blah

then you can just

logs = YAML::load_file('filename')
p logs[:incorrect_string]

cheer!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文