pact-foundation / pact-support

Shared code for Pact gems
MIT License
7 stars 47 forks source link

Ruby 3.0 support #85

Closed iamvery closed 3 years ago

iamvery commented 3 years ago

Problem

We're working to support Ruby 3.0 and have run into some issues with this library. In particular with this line.

Here's a simple reproduction in irb.

iamvery/ruby-3 ~/C/O/pact-support » irb
irb(main):001:0/ r = //
=> //
irb(main):002:1* def r.as_json
irb(main):003:2* end
Traceback (most recent call last):
        4: from /Users/.../ruby/3.0.0/bin/irb:23:in `<main>'
        3: from /Users/.../ruby/3.0.0/bin/irb:23:in `load'
        2: from /Users/.../ruby/3.0.0/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
        1: from (irb):2:in `<main>'
FrozenError (can't modify frozen object: (?-mix:))

I was also able to reproduce this with your test suite. I was hoping to add Ruby 3.0 the build so that it's self-evident, but I don't see Travis being built on this PR. Here's an example from a local run:

1) Pact::ActiveSupportSupport fix_regexp returns the original regexp
     Failure/Error:
       def regexp.as_json options = {}
         {:json_class => 'Regexp', "o" => self.options, "s" => self.source }
       end

     FrozenError:
       can't modify frozen object: (?-mix:moose)
     # ./lib/pact/shared/active_support_support.rb:30:in `fix_regexp'
     # ./spec/lib/pact/consumer_contract/active_support_support_spec.rb:13:in `block (3 levels) in <module:Pact>'
     # ./spec/lib/pact/consumer_contract/active_support_support_spec.rb:16:in `block (3 levels) in <module:Pact>'
iamvery commented 3 years ago

tagging @bethesque on this for visibility

bethesque commented 3 years ago

😱 Bloody active support! It kills me. https://github.com/pact-foundation/pact-support/blob/master/lib/pact/shared/active_support_support.rb#L23

It's going to be a deep dive to work out how to fix this one. I'll have a look at it on my next OSS day (either this Thursday or next Thursday).

iamvery commented 3 years ago

Haha, no worries. I got a good laugh out of that file.

beneath its destructive hooves of destruction

If I am able to give it some more time, I will see if I can make progress as well.

bethesque commented 3 years ago

Follow https://github.com/pact-foundation/pact-support/issues/87 for progress.

bethesque commented 3 years ago

Lolz. Just found the "active support support" equivalent in the Sequel gem.

https://github.com/jeremyevans/sequel/blob/master/lib/sequel/plugins/json_serializer.rb#L105-L118

And I quote:

You can undo the damage done by active_support/json by doing: ...