Explicitely load ostruct so it's compatible with latest JSON gem#49
Explicitely load ostruct so it's compatible with latest JSON gem#49ilyazub merged 2 commits intoserpapi:masterfrom lcmen:fix-hash-extensions-for-latest-json
Conversation
deivid-rodriguez
left a comment
There was a problem hiding this comment.
Bundler daily specs run into this too, thanks for fixing it!
javierjulio
left a comment
There was a problem hiding this comment.
Thanks! We ran into the following error today which this should address.
bundler: failed to load command: turbo_tests (/usr/local/bundle/bin/turbo_tests)
/usr/local/bundle/gems/turbo_tests-2.2.0/lib/utils/hash_extension.rb:4:in `to_struct': uninitialized constant CoreExtensions::OpenStruct (NameError)
|
I've also had to fixed it in #41 (but an explicit PR might be better). |
|
@javierjulio @deivid-rodriguez who can I ping to merge it and release a new version? |
This resolves the following OpenStruct error. There is only 1 reference to OpenStruct in this file, no other references in the code base. ``` NameError: uninitialized constant RSpec::Rails::OpenStruct # ./spec/rspec/rails/example/view_example_group_spec.rb:190:in `controller' # ./spec/rspec/rails/example/view_example_group_spec.rb:196:in `block (3 levels) in <module:Rails>' # /home/runner/work/rspec-rails/rspec-core/lib/rspec/core/example.rb:263:in `instance_exec' ``` This could be caused by a recent gem update like `json` as I encountered this with serpapi/turbo_tests#49 as I use turbo_tests to run my rspec test suite.
This started to occur on recent test suite runs. It may be related to a json gem update that removed the ostruct dependency as I encountered this with turbo_tests and a fix for that is in serpapi/turbo_tests#49 with more details.
|
Closes #52, which I created because such an issue would have saved me 15 minutes (I looked only in Issues, not in PRs). |
|
Thank you @ilyazub ! |
|
Released in v2.2.1: https://rubygems.org/gems/turbo_tests/versions/2.2.1. |
This resolves the following OpenStruct error. There is only 1 reference to OpenStruct in this file, no other references in the code base. ``` NameError: uninitialized constant RSpec::Rails::OpenStruct # ./spec/rspec/rails/example/view_example_group_spec.rb:190:in `controller' # ./spec/rspec/rails/example/view_example_group_spec.rb:196:in `block (3 levels) in <module:Rails>' # /home/runner/work/rspec-rails/rspec-core/lib/rspec/core/example.rb:263:in `instance_exec' ``` This could be caused by a recent gem update like `json` as I encountered this with serpapi/turbo_tests#49 as I use turbo_tests to run my rspec test suite.
|
Thanks all ❤️ (I'm maintainer of json gem) |
|
This PR introduced a problem in Ruby-core CI: ruby/ruby#10496. |
|
@ilyazub I encountered the same JSON gem related error in the rspec-rails repo when submitting a PR. I resolved that issue initially by requiring OpenStruct but since it was only one instance, I replaced it later with a Struct instead due to maintainer's suggestion. I wonder if it would help to do that same replacement here too? In general, it's long been advised to not use OpenStruct anyway. |
|
@javierjulio Makes sense. Thank you for debugging it!
I understood the consequences ( |
|
@ilyazub you're welcome! It was the same error as reported here, essentially a "NameError: uninitialized constant OpenStruct" error message. This is a failed build on rspec-rails from my first PR where that error occurred. I'm not sure I understand the root cause but it's tied to the json gem somehow. The understanding I and others came to elsewhere was it would be best to remove the OpenStruct usage rather than continue to rely on it. |
|
Thank you @javierjulio! rspec/rspec-rails#2755 makes total sense. |
|
Thank you guys for addressing from bigger picture perspective 🙇 . I wasn't aware of the problem in other repos. |
The latest
jsongem version (2.7.2 for the time being) no longer requiresOpenStruct(PR: https://github.com/flori/json/pull/565/files) making this gem incompatible with it.This PR modifies the codebase to explicitly
require 'ostruct'so JSON gem is aware of it but most importantly it makesOpenStructavailable in lib/utils/hash_extension.