pact-ruby: Problem when using `oj` as JSON library.
oj is A fast JSON parser and Object marshaller as a Ruby gem. I tried to used it in my Rails application but looks like pact tests are failing when oj is used as default parser/marshaller.
I have posted an inssue in oj gem already - https://github.com/ohler55/oj/issues/475. Now JSON representation looks ok, but rspec is still failing and it looks like more work than that is required.
I created also sample https://github.com/seban/oj-pact-problem rails (4.2.10) app to reproduce conditions.
Can some one advise me on this one?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 27 (11 by maintainers)
Commits related to this issue
- feat: attempting to recreate https://github.com/pact-foundation/pact-ruby/issues/166 — committed to pact-foundation/pact-support by bethesque 6 years ago
- feat: recreating https://github.com/pact-foundation/pact-ruby/issues/166 — committed to bethesque/oj-pact-problem by bethesque 6 years ago
Thanks @ohler55.
As a summary for future users with the same problem, if you’re using Pact with OJ and you call
Oj.optimize_rails, you also need to callOj.default_options = { create_additions: true }.@seban this is a change that I think belongs in your codebase rather than in the Pact code, so I’m going to close this issue now.
Adding
create_additions: trueto the default options fixed the issue but I noticed that does not show up in the default options so that needs to be fixed. The kicker is that in the older JSON gem thecreate_additionsdefaulted to true. In the more recent that Oj is mimicking it is set to false. To be on the safe side you should explicitly set that since the default can not be counted on being the same from one version to the next.