hofstadter-io / frisby

API testing framework inspired by frisby-js
MIT License
278 stars 27 forks source link

Can't handle period character in json field names #7

Closed snikch closed 8 years ago

snikch commented 8 years ago

Hey - first up, thanks for the work on your library. We're evaluating using it and Iv'e come across an issue with the ExpectJson api.

I have a json response that looks like this:

{
  "error": "Invalid data supplied",
  "fields": {
    "display_name": "display_name is required",
    "ends_at": "ends_at is required",
    "starts_at": "starts_at is required",
    "state.state": "state must be one of the following: \"active\", \"inactive\""
  }
}

I'd love to be able to test this via ExpectJson("fields.state.state", "xxx") but for obvious reasons this isn't possible.

I see two options for fixing this. One is to change the signature of the current api, which would be a backwards incompatible change: ExpectJson(expectation string, path string...). The other option would be to add a new method with that signature, e.g. ExpectJsonAtPath(expecation string, path string...).

Thoughts?

verdverm commented 8 years ago

How about adding a feature to parameterize the separation token ?

like: response~field~state.state

That would make frisby much more flexible and stay backwards compatible too

snikch commented 8 years ago

Sounds good. I can do a PR for this when I'm next in the code.

verdverm commented 8 years ago

awesome, thanks!

verdverm commented 8 years ago

I would add a field and setter function in global.go with the default being '.'

Then use the global field every where like split(path,Golbal.path_separator)

verdverm commented 8 years ago

Global PathSeparater added by #9