-
Notifications
You must be signed in to change notification settings - Fork 63
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
Combining guards #30
Comments
Funnily enough I was looking at something like this this-morning. platform_is :windows do
end xyz if platform_is? :windows ...pairs |
Also I can't think of a useful |
Re
The last usage is the one that seems hard to work around without the possibility to turn off guards. |
I think we should avoid introducing too many extra methods at the top-level, so I think compromising and dropping the extra |
I didn't know about mkspec - is it documented beyond the command line info? I've always thought it would be nice if there were a |
Re mkspec, it's "documented" here: https://github.com/ruby/spec/blob/master/CONTRIBUTING.md#mkspec---a-tool-to-generate-the-spec-structure |
if platform_is :linux or (platform_is :windows and ruby_version_is "2.5")
# specs
end I like that, but as you mentioned, it causes other issues. Maybe something like an env_is [:linux], [:windows, :gte_25] do
end Obviously, there would be need for several symbols defined for 2nd element, since people may prefer to have both a 'greater than or equal' (gte) or a 'less than' (lt) constraint. Thinking six months from now, when 2.3, 2.4, 2.5 and 2.6 will probably all exist... As an aside, I'll look at adding mspec to my doc site. Someday I'll write some code to allow spec style tests to be doc'd. And, sorry for the delay. |
@MSP-Greg The problem with the I'll try to implement: guard -> { platform_is :linux or (platform_is :windows and ruby_version_is "2.5") } do
...
end That should be relatively straightforward. guard_not -> { platform_is :linux or (platform_is :windows and ruby_version_is "2.5") } do
...
end
# or (but it's not trivial to invert so I prefer the one above)
guard -> { platform_is_not :linux and (platform_is_not :windows or ruby_version_is ""..."2.5") } do
...
end I'm not yet convinced Maybe |
About documentation, I am not sure what you want to achieve but there once was a |
Maybe constrain or constraint? |
I implemented it as I applied it in a couple places in ruby/spec in ruby/spec@25d17e1 and previous commits. |
Currently, combining guards is complicated, and is often side-stepped by using shared specs which introduce an extra indirection.
Going forward I would like that guards also support being called without a block and just return true/false. Then with some generic
guard/guard_not
taking a lambda for the guard we could do just likeif/unless
, but also be able to ignore all guards (--unguarded
). I am currently pondering whether--unguarded
is really useful. If not, we could remove it and then just use something like:which I believe is much simpler, but prevents ignoring guards globally (
--unguarded
).The text was updated successfully, but these errors were encountered: