-
-
Notifications
You must be signed in to change notification settings - Fork 906
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
[WIP] Variable definitions #290
Conversation
|
||
class FunctionalTests_DefinitionsSpec: QuickSpec { | ||
override func spec() { | ||
define("one") { return 1 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. You could probably make this even shorter:
define("one") { 1 }
I bet you could also have define
take an @autoclosure(escaping)
parameter, which would allow you to write:
define("one", 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
OK, so this pull request blew me away. Thanks a ton for the test coverage and the detailed message explaining what you did. 👍 And while overall I think this is an interesting approach, ultimately I think it's missing type safety. The casting between I do think, however, Quick should allow users to customize it's behavior as much as possible. We could allow for I think we should look to RSpec as much as possible for guidance here. Some key questions I'd want to research before proceeding here are:
|
Yeah, I see what you mean about the type safety issue, I didn't quite think about that, coming from ruby. Either way, a plugin system sounds like an awesome idea. I'd be happy to help with anything you need. Feel free to contact me via email as well. |
You can have generic methods and functions, but you'll need to link the generic type from its definition to its usage in a way the Swift compiler can track and infer its type. — On Wed, May 6, 2015 at 12:44 AM, Assaf Gelber notifications@github.com
|
I see.. I'll try to think of other ways, I guess. Would be glad to get some pointers or suggestions 🍻 |
Thanks again for the great code and discussion, @agelber! 💐 To keep the pull request tab clean--I'd like only requests in active review to stay there--I'm going to close this pull request in favor of two issues:
|
Hi there!
Background:
I really like the way
let
s work in rspec, and also saw issue #231, so I tried implementing something similar for quick.Implementation:
I added a
Definitions
class which holds a dictionary which maps "variable names" as strings to closures and a dictionary which holds memoized values of those closures.I added a
definitions
property toConfiguration
which can also be used throughWorld
, in a similar fashion to the way hooks are used.So now from anywhere in your tests, you can use
define
(let
was taken 😸) which takes a name and a closure to define a variable andfetch
which takes a variable name and returns the value for that variable. The values are memoized for example and reset between examples (just like rspec).My Problem:
In swift, this works just as expected, the tests I wrote are passing and everything is happy.
In Objective-C, however, my last test (which is identical to the swift one) is failing. Instead of
number
being4
, I get2
again. My assumption is that the value ofmutatingNumber
is being captured in the block even though I marked it as__block
. I am not completely sure why and I couldn't get this to work, so I though one of you guys might have a solution to this.I really appreciate the work you've all been putting into Quick and would really love to see this feature making it's way in if we can figure this out.
Let me know if there's any more information I could give or any other thing I can do!
Thanks! 🍻