-
Notifications
You must be signed in to change notification settings - Fork 62
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
More readable syntax? #300
Comments
Hi! I'm just poking around here, looking into this project and was wondering the same thing. There is some insight here: #272 |
That's disappointing that the even better rspec syntax got broken, but the syntax I mentioned above can be achieved by returning maps with anonymous functions attached to them. |
Hey @AlexMcConnell ! A couple of years ago ESpec had syntax like:
And, actually, that was an initial idea behind ESpec - mimic RSpec syntax. Your idea looks interesting. Could you please implement a simple proof-of-concept? So we can discuss this in details. |
Hi, I think we could easily implement this syntax by returning a map with an anonymous function as value to expect(actual).to.(eq(expected)) And we might get away with having it along the current one (so as not to break backwards compatibility). We could go ahead and implement the very thing expect(actual).to.eq.(expected) but we might not be able to maintain backwards compatibility. And I don't think we can have assertions with different arities. For example we could not have both of these expect(1).to.be.(1)
expect(2).to.be.(:>, 1) as anonymous functions cannot have multiple arities. But since there are not that many assertions with multiple arities we could change their syntax. For the example above it could be expect(1).to.be.(1)
expect(2).to.be.({:>, 1}) However, this would be a big change to the end user and we should consider the risks and implications before implementing it. And maybe other syntax ideas. |
Sounds great @andrei-mihaila ! |
Hey @antonmi Just in case it wasn't clear, this was all I did:
I didn't explore it in any sort of depth though, as my knowledge of Elixir is pretty limited. Also not really thrilled with the |
For what it's worth, I actually like the current |
I don't understand why you chose to use this for your syntax:
expect actual |> to(eq expected)
rather than this:
expect(actual).to.eq.(expected)
The second seems far more readable to me. Like, obviously the pipe operator is a core part of Elixir to the point that everyone programming in Elixir is going to understand it, but simple English is still more readable, and that goes doubly so when the more English syntax ends up being almost exactly the same as Ruby and close to the same as JavaScript, and triply so when the basic point of this library is to make more readable tests than ExUnit, in a style more like RSpec.
The text was updated successfully, but these errors were encountered: