Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

rails 3.0.2 + jasmine 1.0.1.1 + json_pure == dll_hell.rb

Ken Mayer
Tuesday, November 23, 2010

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.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

4 Comments

  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 1.0.1.1, 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.

    November 24, 2010 at 8:48 am

  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([])`

    November 25, 2010 at 9:54 am

  3. Johan says:

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

    December 13, 2010 at 3:29 pm

  4. Ken Mayer says:

    I’ve posted a patch to Rails Core. Here’s the Lighthouse ticket, [#6047](https://rails.lighthouseapp.com/projects/8994/tickets/6047-jsongenerate-raises-exception-in-v302-json_pure-143#ticket-6047-8, “#6047). If you like the fix, let the core team know that it’s important to you for the next release.

    December 16, 2010 at 8:12 pm

Add New Comment Cancel reply

Your email address will not be published.

Ken Mayer

Ken Mayer
San Francisco

Recent Posts

  • Sencha Touch BDD – Part 5 – Controller Testing
  • Sencha Touch BDD – Part 4 – PhantomJS
  • Sencha Touch BDD – Part 3 – Testing Views and Mocking Stores
Subscribe to Ken's Feed

Author Topics

bdd (5)
bloggerdome (5)
jasmine (6)
javascript (5)
mobile (6)
sencha (5)
meta programming (1)
refactoring (1)
ruby (1)
agile (18)
planning (1)
design (2)
heroku (3)
rails (8)
workflow (5)
cucumber (3)
testing (4)
performance (3)
devops (1)
jquery (2)
careers (1)
college job fairs (1)
hiring (1)
jobs (1)
recruitment (1)
bundler (3)
facebook (1)
json (1)
nginx (1)
movember (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >