Rails 没有获取 .yaml.erb 装置?
我正在尝试为Rails Backend设置Circle CI以自动进行大量测试,其中一些测试是使用带有ERB标签的YAML固定装置的传统代码。我使用的是Ruby 2.6.9,Rails 5.2.6,Circle CI Docker Image拒绝解析这些文件的格式不好。
固定装置的外观示例:
<%mt = medtest.new(结果:“正”)%> covid19_positive: 用户:用户1 MEDTEST_TYPE:COVID-19 encrypted_result:<%= mt.encrypted_result%> encrypted_result_iv:<%= mt.Encrypted_result_iv%> result_bidx:<%= medtest.generate_result_bidx(“ pastic”) test_date:<%= 10.days.ago.to_s(:db)%> create_at:<%= 10.days.ago.to_s(:db)%> 共享:是的
在Circe Ci Docker Image中运行测试时的错误
runtimeerror:包装不可限制的例外:activerecord :: fixture :: formaterror:yaml错误发生了parsing/home/circleci/proect/project/test/test/fixtures/fixtures/medtests.yml。请注意,必须使用空格始终如一地缩进YAML。不允许标签。请看一下http://www.yaml.org/faq.html 确切的错误是: 参数:必须指定密钥 测试/固定装置/MEDTESTS.YML:1:在“ get_binding”中
我尝试将ERB标签从YAML文件中取出,而只是硬编码动态值,但这会引发其他问题(我几乎必须重构A 1000 A 1000测试,如果我想这样做)。建议的解决方案是将.yaml.erb格式用于固定装置而不是.yml格式,但似乎在更改格式后,Rails似乎没有拾取固定装置!关于如何用最少的重构来处理这一点的任何想法?
PS:所有测试都在多台机器上通过,没有任何问题。
I'm trying to set up Circle CI for a Rails backend to automate a fair amount of tests, some of the tests are legacy code that uses YAML fixtures with erb tags. I'm using a Ruby 2.6.9, Rails 5.2.6, Circle CI docker image is refusing to parse those files for bad formatting.
An example of how the fixtures look :
<% mt = Medtest.new(result: "Positive") %> covid19_positive: user: user1 medtest_type: COVID-19 encrypted_result: <%= mt.encrypted_result %> encrypted_result_iv: <%= mt.encrypted_result_iv %> result_bidx: <%= Medtest.generate_result_bidx("Positive").inspect %> test_date: <%= 10.days.ago.to_s(:db) %> created_at: <%= 10.days.ago.to_s(:db) %> shared: true
error when running test in Circle CI docker image
RuntimeError: Wrapped undumpable exception for: ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /home/circleci/project/test/fixtures/medtests.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was: ArgumentError: must specify a key test/fixtures/medtests.yml:1:in `get_binding'
I tried taking the erb tags out of the yaml files and just hardcoding the dynamic values instead but that brings forward other issues (pretty much I have to refactor a 1000 tests, line by line if I want to do that). A suggested solution was to use .yaml.erb format for the fixtures instead of .yml format but it seems that Rails is not picking up the fixtures after changing the format! Any ideas on how to deal with this with minimum refactoring?
PS: All tests pass locally on multiple machines without any issues.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:事实证明,这不是YAML解析问题,当Rails加载固定装置时,您还可以获得参数错误,如果您使用的是动态YAML可能来自模型,就我而言,在我的情况下,这是一个缺失的环境变量,破坏了该变量以回报阻止固定装置的型号。
UPDATE: turned out it's not a yaml parsing issue, when rails loads fixtures, you can also get argument errors, which if you are using dynamic yaml's can be coming from your models, in my case, it was a missing environment variable that broke the models which in return stopped the fixtures from loading.