Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you get into an array inside an object? #30

Closed
fmorales opened this issue Dec 10, 2014 · 10 comments
Closed

How do you get into an array inside an object? #30

fmorales opened this issue Dec 10, 2014 · 10 comments

Comments

@fmorales
Copy link

Here is the json that is giving me greif
https://gist.github.com/fmorales/5b21b301c5e8ae39118c

I am trying to get to value7 under WhatIsThis. WhatIsThis is an object, and value7 is an array under it. I am trying to get to it with:
expect_json_types('array2..WhatIsThis..array3.0', {value7: :string_or_null})

I get an error that I am getting a hash. I looked in the docs for how I access a hash, but I can't find anything. Help!

@sethpollack
Copy link
Collaborator

try expect_json_types('array2.0.WhatIsThis.array3.0', {value7: :string_or_null})

@sethpollack
Copy link
Collaborator

I just tried it with expect_json_types('array2.0.WhatIsThis.array3.0', {value7: :string_or_null}) and that worked fine for me. Let me know if it works for you?

@fmorales
Copy link
Author

I just tried expect_json_types('array2.0.WhatIsThis.array3.0', {value7: :string_or_null})

I got
NoMethodError:
undefined method `[]' for nil:NilClass

@sethpollack
Copy link
Collaborator

hmm, what version of airborne are you using?

@fmorales
Copy link
Author

0.1.8

On Dec 10, 2014, at 4:39 PM, Seth Pollack notifications@github.com wrote:

hmm, what version of airborne are you using?


Reply to this email directly or view it on GitHub.

@brooklynDev
Copy link
Owner

@fmorales I just tried using the following snippet of code:

require 'airborne'

describe 'issue 30' do
  it 'gets value7' do
    get 'https://gist.githubusercontent.com/fmorales/5b21b301c5e8ae39118c/raw/2e41a8a6569d9b11ef02e9a76ca4165a81ae0859/gistfile1.json'
    expect_json_types('array2.0.WhatIsThis.array3.0', {value7: :string_or_null})
  end
end

and just like @sethpollack is experiencing, it works correctly. Can you verify that your code is doing the same thing?

@fmorales
Copy link
Author

I tried dropping your code snippet into my harness, and it works. I am still not having any luck with getting into the same structure myself. I'm at a loss for what I am doing wrong.

@fmorales
Copy link
Author

I figured out the problem, but not the solution. the key 'value7' is not always present. How do I test for it being a string_or_null if it is itself there_or_null. Is there a way to do that?

@brooklynDev
Copy link
Owner

You should be able to wrap it in a call to optional

require 'airborne'

describe 'issue 30' do
  it 'gets value7' do
    get 'https://gist.githubusercontent.com/fmorales/5b21b301c5e8ae39118c/raw/2e41a8a6569d9b11ef02e9a76ca4165a81ae0859/gistfile1.json'
    expect_json_types('array2.0.WhatIsThis.array3.0', optional({value7: :string_or_null}))
  end
end

We put lots of effort into the documentation, please check them out to see if they help you out:

https://github.com/brooklynDev/airborne/blob/master/README.md

@fmorales
Copy link
Author

Thank you so much for you help. I had tried that. I must have been using it wrong. Thank you for the clarifacation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants