Comments (7)
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.
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.
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.
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.
@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.
@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.
Yep, makes sense. Thanks.
from elixir_mock.
Related Issues (8)
- defmock_of doesn't work without importing Mockex
- creating mocks in test setup causes mock module name conflict warnings HOT 2
- Private functions on mock modules not accessible by public functions
- Bad messaging when call verification fails for matchers
- Inject context into mock definitions HOT 1
- Add "was called with any number of arguments" verification
- Pattern matching in stubbed functions does not record call args correctly HOT 1
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 elixir_mock.