collectiveidea / json_spec

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

Add haveJsonValue matcher #84

Open EleanorRagone opened 9 years ago

EleanorRagone commented 9 years ago

Adds a helper to match a specific value in JSON

skalee commented 9 years ago

This pull request has couple of flaws:

  1. It adds files which shouldn't be there (*.gem, environment configs)
  2. Contains no documentation updates.

This effect can be achieved in the other ways, and that has been stated previously, see #23. That said, I would welcome matcher like this. +1, but changes are required before merge.

With such matchers, I could write ActiveModel::Serializers examples like this one:

describe ApiV1::SomeSerializer do

  subject do
    serializer_class.new(model, options).to_json
  end

  let(:serializer_class) { ApiV1::SomeSerializer } # this can be improved with RSpec metadata
  let(:model) { SomeModel.new("What a beautiful model") }
  let(:options) { Hash.new } # to be overriden in various contexts

  it { is_expected.to have_json_value("What a beautiful model").at_path("pretty_name") }
end

Which would be really great. Currently I can either write "What a beautiful model".inspect or %q["What a beautiful model"] which seems inferior and is error-prone to me and my team mates.

Getting comparably readable effect with #parse_json doesn't seem easy to me.

mcnelson commented 6 years ago

This PR appears dead. I would like to use this new matcher, see other PR above ^