Comments (7)
Hi! I'm just poking around here, looking into this project and was wondering the same thing. There is some insight here: #272
from espec.
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.
from espec.
Hey @AlexMcConnell !
Sorry for the late response.
A couple of years ago ESpec had syntax like:
expect(actual).to eq(expected)
And, actually, that was an initial idea behind ESpec - mimic RSpec syntax.
But, as @sodapopcan mentioned, I had to get rid of it because of changes in OTP 21.
Your idea looks interesting. Could you please implement a simple proof-of-concept? So we can discuss this in details.
from espec.
Hi,
I think we could easily implement this syntax by returning a map with an anonymous function as value to :to
(as @AlexMcConnell says)
expect(actual).to.(eq(expected))
And we might get away with having it along the current one (so as not to break backwards compatibility).
I vaguely remember discussing this with @antonmi (might be wrong) and deciding not to have it for fear they will change the dot special form behaviour again. They don't say anything about accessing map fields in the doc.
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.
from espec.
Sounds great @andrei-mihaila !
But I have to check this in detail.
It's been a while since this functionality was built. :)
from espec.
Hey @antonmi
Also sorry for the late response. 😁
Just in case it wasn't clear, this was all I did:
def xpected(actual) do
%{
:to => %{
:eq => fn (expected) -> expect actual |> to(eq expected) end
}
}
end
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 eq.(
part of that, but what can you do? 😐
from espec.
For what it's worth, I actually like the current |>
syntax. I think it's easy to reason about, and it matches what the rest of my Elixir code looks like.
from espec.
Related Issues (20)
- Dynamic mocking with `:meck.expect/4` HOT 2
- .formatter.exs is not included in published package HOT 1
- Task.async_stream for async examples? HOT 5
- behaviour of `subject!` feels broken HOT 4
- Erlang/OTP 21 Tuple Call support removed HOT 5
- `have` matcher for maps with string keys? HOT 3
- ESpec with OTP 21 (ArgumentError) HOT 2
- Doctests failing since the deprecation of old documentation format (elixir 1.7) HOT 3
- Feature: scoped_before HOT 1
- Let evaluation in shared specs not working correctly HOT 3
- Allow asserting that a mock will be called within a timeout HOT 1
- Make test runner survive after process death HOT 3
- Elixir 1.10 compatibility HOT 7
- Run ExUnit and Espec at the same time HOT 6
- espec 1.8.2 fails to compile in elixir 1.11.0 HOT 1
- Any documentation about the different formatter options
- mix espec.watch HOT 2
- mix espec.init doesn't work in umbrella apps HOT 4
- Elixir 1.16 compatibility HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from espec.