collectiveidea / json_spec

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

include_json can't test parsed array response #40

Closed marshallshen closed 11 years ago

marshallshen commented 11 years ago

Correct me if I am wrong, but currently json_spec can't test the following scenario:

Given actual (json object) and expected(hash):

JSON.parse(actual) [{"name" => "Mike"}, {"name" => "Abby"}] expected {"name" => "Abby"}

actual.should include(expected.to_json) => fail because the following is false: [{"name" => "Mike"}, {"name" => "Abby"}].include?({"name" => "Abby"})

Maybe we should create include_partial_json ? If so, I will try to submit a patch.

laserlemon commented 11 years ago

I don't think the example code you gave evaluates to false. I'm traveling at the moment, but have you tried that code?

marshallshen commented 11 years ago

Correct me if I am wrong, but currently json_spec can't test the following scenario:

Apologies, I didn't paste in the real test, please see the updates in the following

Given actual (json object) and expected(hash):

JSON.parse(actual) [{"name" => "Mike", "gender" => "male"}, {"name" => "Abby", "gender" => "female"}] expected {"name" => "Abby"} actual.should include(expected.to_json) => fail because the following is false: [{"name" => "Mike", "gender" => "male"}, {"name" => "Abby", "gender" => "female"}].include?({"name" => "Abby"})

Also I think rather than adding include_partial_json, adding more support inside include_json should be efficient.