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

is_some() cannot be followed by has_length() #11

Open
kirushik opened this issue Apr 12, 2017 · 3 comments · May be fixed by #12
Open

is_some() cannot be followed by has_length() #11

kirushik opened this issue Apr 12, 2017 · 3 comments · May be fixed by #12

Comments

@kirushik
Copy link

I'm trying to build some assertions on serde_json::Value (parsing result from my JSON-RPC api).
I'm doing this:

let json : Value = serde_json::from_str(&query_result).unwrap();
assert_that(&json["result"].as_array()).is_some().has_length(3);

and expect it to work, since is_some() returns Spec over the contained object.

Surprisingly, I'm getting an error:

error: no method named `has_length` found for type `spectral::Spec<'_, &std::vec::Vec<serde_json::Value>>` in the current scope

What am I doing wrong here?

PS. I'm on Rust 1.16 stable, on Windows (stable-x86_64-pc-windows-msvc).
Spectral version is 0.6.0, installed from crates.

@kirushik
Copy link
Author

At the same time

assert_that(&Some(vec![1,2,3])).is_some().has_length(5);

works as expected, so my issues is somewhere in spectral+serde combination...

@kirushik
Copy link
Author

Well,

assert_that(&Some(&vec![1,2,3])).is_some().has_length(5);

fails in the same way as my original one did.

So the issue is with that additional reference inside of Option, sorry for not being patient enough right from the beginning.

Looks like this is an additional, not yet implemented feature.

Should I keep this issue open then?
Perhaps I'll submit a PR with an implementation, but no promises or estimates...

@cfrancia
Copy link
Owner

Looks like it's missing an implementation for &Vec. I guess I never thought of the case where you'd be unwrapping a reference to a Vec via is_some().

Simple solution would be to just copy-paste the existing implementation with the new bound, but it'd be nice to just use a macro or something to clean it up a bit.

I'm happy to wait for you to submit a PR, or otherwise I'm also happy to fix it up when I have a moment.

@kirushik kirushik linked a pull request Apr 26, 2017 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants