Giter Site home page Giter Site logo

Comments (7)

wanderanimrod avatar wanderanimrod commented on July 28, 2024 1

No it's okay. I just wanted to knw what is more pressing for you so I start with that. I'll look at the Typespecs and update this issue with progress as I go.

Thanks again for your contribution.

from elixir_mock.

wanderanimrod avatar wanderanimrod commented on July 28, 2024

Hi @facto,

I don't think we should make the library read typespecs and force mocks to adhere to them. Elixir's Behaviours do something very similar to what you are trying to achieve. I would prefer we go with allowing mocks to be defined based on behaviours. I think that might be a cleaner way to get you to where you want to go.

Am I understanding you right?

from elixir_mock.

joshrieken avatar joshrieken commented on July 28, 2024

Thanks, @wanderanimrod.

I think that would work great when generating mocks for modules that already implement behaviours. But not all modules do, so enforcing adherence to existing typespecs, if any, would also be useful I think.

from elixir_mock.

wanderanimrod avatar wanderanimrod commented on July 28, 2024

Looks like examining typespecs at runtime is possible. I'll look into this and see what can be done.

If you had to chose between Behaviours and Typespecs support, which one would you do first?

from elixir_mock.

joshrieken avatar joshrieken commented on July 28, 2024

@wanderanimrod Hmm... Either would be fine. Personally, I'd probably utilize the typespecs more. I'm happy to try my hand at the typespecs if you want to split the work.

from elixir_mock.

wanderanimrod avatar wanderanimrod commented on July 28, 2024

@facto ,

Whereas you can inspect typespecs attached to a function using Kernel.Typespec.beam_specs/1, you cannot force functions to completely adhere to these specs. Specifically, you cannot enforce that a function's arguments or its return value are of a certain type precisely because type information is not available at compile time in elixir. Tools like Dialyzer have a lot of elaborate tricks but still cannot catch all type-related errors at compile time. That's is why they resort to "optimisitic type checking".

ElixirMock currently does not allow functions that don't match original module functions by name and arity. That takes care of the arity aspect of type specs. It deosn't take care of the type aspect for reasons explained above.

I feel therefore that the safety measures already present are as far as we can go in a dynamically typed environment.

Let me know if this is clear. I'll close this issue for now.

from elixir_mock.

joshrieken avatar joshrieken commented on July 28, 2024

Yep, makes sense. Thanks.

from elixir_mock.

Related Issues (8)

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.