rspec / rspec-rails

RSpec for Rails 6+
https://rspec.info
MIT License
5.14k stars 1.03k forks source link

Fix uninitialized constant RSpec::Rails::OpenStruct error #2754

Closed javierjulio closed 2 months ago

javierjulio commented 2 months ago

This started to occur on recent test suite runs e.g. #2752, #2753. It may be related to a json gem update (example) that removed the ostruct dependency as I encountered that with turbo_tests which I use to run my rspec test suite.

pirj commented 2 months ago

Thank you!

javierjulio commented 2 months ago

@pirj thank you for the quick turnaround! I'll go back to update the other PR and see what errors remain.

JonRowe commented 2 months ago

@pirj this needs to be reverted or the require moved to a sub process... it could cause dependency based issues for us / our users

javierjulio commented 2 months ago

@JonRowe I can try to help. Why would it need to be reverted if the require 'ostruct' is just in a spec file that only affects the test suite? I can submit a revert if it's really necessary. Do you have an example of what I can follow for require usage to resolve the OpenStruct error in a safe manner?

pirj commented 2 months ago

We could just use a Class.new to create an interface that that view helper needs.

javierjulio commented 2 months ago

That would be ideal over using OpenStruct since it's been a long time now that Ruby has advised to not use it. I'm not familiar with the requirements for this project so likely missing something. Can I help with a PR to do that instead?

JonRowe commented 2 months ago

the require 'ostruct' is just in a spec file that only affects the test suite?

The reason for this policy is that it means we could inadvertandly then use openstruct and cause breakages.

The replacement in #2755 is much better thank you.

javierjulio commented 2 months ago

Yes, I think it's better too to avoid OpenStruct if possible. Thanks!