collectiveidea / json_spec

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

Helpers#parse_json to not parse unless a String #30

Closed rudionrails closed 12 years ago

rudionrails commented 12 years ago

Hi,

I currently have a setup that had a last_json method already implemented before migrating to json_spec for cucumber testing. The method already returned a parsed JSON, which is not compatible since json_spec wants to parse it again from a string.

I committed a change to only parse the JSON in case it's a string (else return the given option). I can't see a reason why last_json should only be the last_response.body string (or similar) and not already a Hash/Array.

Would that be something you could merge into the main branch?

Best, Rudi

laserlemon commented 12 years ago

Thanks for your work, Rudolf. I like the idea but I would like to see at least another higher level test for this. Because there's been no contract that last_json will always be run through parse_json (although that seems to be the case right now), we need to ensure that each of the matchers work properly when fed Ruby rather than JSON. Make sense? Thanks again!