Home > Back-end >  Rails not picking up .yaml.erb fixtures?
Rails not picking up .yaml.erb fixtures?

Time:04-06

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.

CodePudding user response:

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.

  • Related