Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

rails 3.0.2 + jasmine + json_pure == dll_hell.rb

The 3.0.2 update to rails made a change in active support that creates an interference pattern failure in the jasmine-gem. Not jasmine, itself, mind you, just the standalone server that runs the jasmine tests, and not the server, but just the report runner. Thus, your tests are all green, but the jasmine suite fails anyway. You might see this error:

undefined method `merge' for #<JSON::Pure::Generator::State:0x102181890> (NoMethodError)

The selenium driver inside the jasmine gem is loadingjson_pureunless it can find an already loaded JSON class. json_pure was hacked by rails for other reasons, but it breaks JSON.generate. Madness ensues.

To fix this, you need to use something other than json_pure, at least in your test suite. The fix, fortunately, is pretty simple. Add the following line to your Gemfile

gem "json", "1.4.6"

This will load the json gem built with native extensions. The version number is not necessary to fix this problem, but we try to lock down versions as a standard practice.

This was maddeningly painful to pinpoint. I’m not sure if there’s a long term solution to the problem either. You need a JSON library, but so do many others. Monkey patching the class seems really handy, but is prone to break behaviors.

  1. DWF says:

    This issue is not Jasmine-specific but rather any gem that patches JSON (pure or native) after Rails does borks the monkey patches that Rails expects.

    The Jasmine gem only needs JSON when running in CI mode and only to extract results from the reporter’s DOM to provide them in your CI log.

    As of, the Jasmine gem should only `require “json-pure”` when the Selenium driver is instantiated. Rails should not be loaded and thus you shouldn’t have this problem any longer.

    I’m surprised that this fix didn’t work for you. I’ll want to take a look at your project.

  2. Ken Mayer says:

    Agreed. It’s definitely caused by Rails. I can replicate the error on a rails console with just this: `JSON.generate([])`

  3. Johan says:

    Thanks for the comments, I have the same error.
    The change on gemfile solve the issue.

  4. Ken Mayer says:

    I’ve posted a patch to Rails Core. Here’s the Lighthouse ticket, [#6047](, “#6047). If you like the fix, let the core team know that it’s important to you for the next release.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *