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

Spec: cast values for be_nil and be_a expectations #8369

Closed
straight-shoota opened this issue Oct 23, 2019 · 0 comments · Fixed by #8412
Closed

Spec: cast values for be_nil and be_a expectations #8369

straight-shoota opened this issue Oct 23, 2019 · 0 comments · Fixed by #8412

Comments

@straight-shoota
Copy link
Member

A way to solve this forum request

Currently, when validating the type of a value in spec, we need to restrict the type afterwards in order to call restricted methods on the sample:

index = "foo".index('o')
index.should_not be_nil
foo[index.not_nil!].should eq('o')

The not_nil! is needed because the compiler has no way to know that the should_not be_nil means that index will not be nil.

The idea is to let be_nil and be_a expectations return the value with appropriate type restriction:

index = "foo".index('o')
index = index.should_not be_nil
foo[index].should eq('o')

Basically, the result of obj.should_not be_nil will return obj as a non-nil object.

The same applies for obj.should be_a(T) and obj.should_not be_a(T).

An implementation was submitted in #8240, but it should be overhauled.

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

Successfully merging a pull request may close this issue.

1 participant