waterlink / rspec-json_expectations

Set of matchers and helpers to allow you test your APIs responses like a pro.
https://www.relishapp.com/waterlink/rspec-json-expectations/docs
MIT License
140 stars 23 forks source link

Implement include_unordered_json #17

Closed esjee closed 8 years ago

esjee commented 8 years ago

This is intended as a replacement for include_json UnorderedArray(...). Personally I think this is a slight improvement in the case where expected is an array; curious to know what you think of it.

Not sure if it's a good idea to automagically travel expected, and convert any arrays to UnorderedArrays.

E.g, transform this

{
  results: {
    foo: bar,
    foobar: ["one foo", "two foo"]
  },
  baz: ["qux"]
}

into this:

{
  results: {
    foo: bar,
    foobar: UnorderedArray.new(["one foo", "two foo"])
  },
  baz: UnorderedArray.new(["qux"])
}

Moreover, I would like to DRY this up. I don't know a lot about writing RSpec matchers, but (by the looks of it)[http://makandracards.com/makandra/662-write-custom-rspec-matchers], if I were to make a matcher class, it looks like users would have to include this, which is a bit of a shame. Could also use some instance_eval magic here, but not sure if that's such a great idea.

Details aside, I look forward to hearing your thoughts on this suggestion. Let me know what you think!

esjee commented 8 years ago

I removed the duplicate code. Think this is a bit more acceptable. :)

Let me know what you think!

waterlink commented 8 years ago

Looks good to me!

waterlink commented 8 years ago

Thanks! I will release new version today evening.

waterlink commented 8 years ago

@esjee 1.4.0 is released to the rubygems

esjee commented 8 years ago

Great! Thank you!