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

Feature Request: Add API for testing Array size #17

Closed
PikachuEXE opened this issue Oct 22, 2014 · 5 comments
Closed

Feature Request: Add API for testing Array size #17

PikachuEXE opened this issue Oct 22, 2014 · 5 comments

Comments

@PikachuEXE
Copy link
Contributor

I am using json_spec currently and just started using this gem.

I like how I can validate the types easily with expect_json_types.
But I found no API for Array size, which is very common when writing spec for collection endpoints.
(Like expect_json_size)

I am staying with have_json_size from json_spec at the moment.

@brooklynDev
Copy link
Owner

Hey @PikachuEXE, I appreciate your feedback, but I'm afraid of feature creep. This is already possible with airborne using a block like so:

it 'should validate array size' do
  get '/array_api' #api that returns {data: [1,2,3,4]}
  expect_json_types({data: -> (data){expect(data.length).to eq(4)}}
end

I'll admit it's not as nice as having a specialized function for array size, but I don't think we should add a function for every variation that people come across. This was the intent of the blocks, where you can just use RSpec's robust expectation library.

I'm open to feedback though, and if you/others disagree, I'll reconsider.

@PikachuEXE
Copy link
Contributor Author

I have added one to a wiki page.

@brooklynDev
Copy link
Owner

OK, I've changed my mind 😄 I took a look at your code, and I like it, I was thinking about going with a different approach that would have been slightly more invasive.

Go ahead and submit a pull request (please add tests and documentation as well) and I'll merge it. Thanks for the effort!

@PikachuEXE
Copy link
Contributor Author

I tried adding internal methods but didn't work for unknown reason.
But since you already have a way/example for custom validation, I thought let's don't waste it.

PR will be created later.

@brooklynDev
Copy link
Owner

Thanks for your pull request. I'm closing this issue since I've merged your pull request: #18

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

2 participants