collectiveidea / json_spec

Easily handle JSON in RSpec and Cucumber
rubygems.org/gems/json_spec
MIT License
919 stars 114 forks source link

LoadError: cannot load such file -- [{ 'key':'value' }] #27

Closed halissonvit closed 12 years ago

halissonvit commented 12 years ago

I'm trying to use json_spec with cucumber, but using the step:

  Then the JSON should be:
  """
  {
    'key':'value'
  }
  """

The error is in the helpers.rb file, in the method:

  def multi_json_load(json)
    MultiJson.respond_to?(:load) ? MultiJson.load(json) : MultiJson.decode(json)
  end

Using just MultiJson.decode(json) works fine.

Sorry for my bad english x;

halissonvit commented 12 years ago

I'm using Ruby 1.9.3 and Rails 3.2

laserlemon commented 12 years ago

Thanks for the report, Halisson. What version of MultiJson are you using?

halissonvit commented 12 years ago

gem list multi_json * LOCAL GEMS *

  multi_json (1.3.2, 1.2.0)
laserlemon commented 12 years ago

Hmm, could you please test under each version in isolation?

laserlemon commented 12 years ago

If you have a Gemfile.lock, could you please throw that into a Gist and link to it here?

sferik commented 12 years ago

It's best not to use MultiJson.respond_to?(:load), since Kernel (which defines a load method) gets mixed in to Object. I'd recommend using MultiJson.adapter as a proxy to detect MultiJson.load, since those two methods were added at the same time. See https://github.com/rails/rails/pull/5896/files as an example.

laserlemon commented 12 years ago

Thanks @sferik. @halissonvit, I can't reproduce the problem locally on either version of multi_json. Please provide your Gemfile.lock when you're able and maybe I can track this down. I'd like to confirm that Erik's suggestion really does solve your problem. Thanks.

halissonvit commented 12 years ago

My Gemfile.lock https://gist.github.com/2554748

Thank's for the fast response

sferik commented 12 years ago

There's no longer a need to feature-detect in the latest version of MultiJson (1.3.4). decode is an alias of load that no longer prints deprecation warnings.

laserlemon commented 12 years ago

New version released, moving back to decode until the next major version of multi_json ships.