collectiveidea / json_spec

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

In Ruby < 1.9.2 the % operator doesn't take %{} format strings #34

Closed foozmeat closed 11 years ago

foozmeat commented 11 years ago

I added this to my helper file to work around it.

if RUBY_VERSION < '1.9.2'
  class String
    old_format = instance_method(:%)

    define_method(:%) do |arg|
      if arg.is_a?(Hash)
        self.gsub(/%\{(.*?)\}/) { arg[$1.to_sym] }
      else
        old_format.bind(self).call(arg)
      end
    end
  end
end
laserlemon commented 11 years ago

Thank you for posting the issue. As of v1.0.0, json_spec dropped Ruby 1.8 support, in large part because of this JSON memory functionality. That and Ruby 1.8 is on its way out. See:

https://github.com/collectiveidea/json_spec/compare/c0f2e07...a1dc71a

Thank you!