Giter Club home page Giter Club logo

Comments (7)

sodapopcan avatar sodapopcan commented on August 27, 2024

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.

AlexMcConnell avatar AlexMcConnell commented on August 27, 2024

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.

antonmi avatar antonmi commented on August 27, 2024

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.

andrei-mihaila avatar andrei-mihaila commented on August 27, 2024

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.

antonmi avatar antonmi commented on August 27, 2024

Sounds great @andrei-mihaila !
But I have to check this in detail.
It's been a while since this functionality was built. :)

from espec.

AlexMcConnell avatar AlexMcConnell commented on August 27, 2024

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.

LandonSchropp avatar LandonSchropp commented on August 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.