Comments (8)
Yes attr_*
methods are not added to the mock. I've never yet needed them, but there is no reason we can't do them the same way I just added alias_attribute
.
from active_mocker.
I think your goals and our goals may be slightly different. Not misaligned, just we are probably coming from completely different angles to different problems. We have a huge application with a test suite that takes (non-parallelized) about 2.5-3hrs. We still haven't successfully gotten active_mocker to get one of our full specs files to pass, but it is looking promising the tests we have seen passing are 100s or 1,000s of times faster.
Now I think I understand the goal of this project more, as I hadn't noticed the idea of mocking out user-defined methods until we had invested quite a bit of time in it.
Ideally if we can get active_mocker to copy across our application defined methods (and accessors etc) then we may be closer to cutting hours from the test suite time and retaining the same level of confidence. This will hopefully open up a completely different paradigm of development style and make everyone much happier. And ideally make a fantastic tech blog post too.
Now I would prefer to be in a situation where we have a smaller test suite where every unit test is a genuine unit test and dependencies are clearly defined and coupling is tiny. But the reality is we are looking for a drop-in replacement for AR on a large app that spins up lots of factories that spin up more factories etc. I'm a consultant and this pattern seems to be the most common on lots of Rails apps I've worked on. Probably because development of new features is easy that way, and it only gradually becomes a problem.
It seems feasible to pull in user defined methods by using Method#source_location
and a configurable setting that just looks in app,lib etc. I've done something very similar before in https://github.com/markburns/delfos
Would you be open to a PR that supports copying these methods across into the mocks (maybe as an overridable thing)?
We'll probably be going ahead anyway with it, but it's always nicer where possible to stay aligned with the original author's thoughts on how/if something should be done.
from active_mocker.
Supporting user defined method would mean you'd need to support the entire active record api, even running SQL strings. This would be an infinite amount of work. There is an assumption that included modules are safe to run, an assumption that I know is not always true, but non the less the way I've used it.
You could try moving your methods in modules.
Making this gem a drop in replacement for active record is not what I'm interested in, the support cost, besides the developer time would be to great.
from active_mocker.
Rather than e.g. SQL strings, which I agree would be painful to support.
What I'm really thinking of is being able to test methods like the ones you might suggest putting into modules.
Things that might depend on an associated object built with a factory and say iterate over and join some fields or something like that. Basically, simple methods only doing things with attributes and associations.
As far as I can see, all stuff that is supported already, but instead of mocking out methods allowing them to execute against the mocks and factory generated attributes and associations.
Then we can just run the specs, determine the ones that passed, then move these over to be our new active_mocker specs. Slash some test run times and allow focusing more time on improving other slower tests in other ways.
from active_mocker.
Maybe you are right that if it gets the 80% done and is really useful, then the support burden would become huge as the expectation to do the remaining 20% may be great
from active_mocker.
Let me think about importing user defined methods into the mock. It's a big change in the current paradigm, but the functionally it's the same as running user defined method from modules in the mock. Really this would most likely leek over for the need for scope
s too.
from active_mocker.
Absolutely. Actually it makes sense for us to at least try out putting some of the instance methods into modules to see how far we get with that approach. If it is only e.g. 2% of tests that end up passing this way then we'll probably want to rethink the strategy completely, and there is little incentive for us to try and drive this project in that direction. If it is 80% then there is a clear benefit (at least for us) to going down this route.
from active_mocker.
Willing to accept a PR for this, but it does not provide any benefit for my self or enough benefit for the general user for me to develop.
from active_mocker.
Related Issues (20)
- Correctly Support many through
- Minitest support? HOT 1
- missing forwardable dependency HOT 2
- Getting "ActiveMocker.safe_methods is unable to find methods: __missing_class_macros__" error for ruby 2.5.5 HOT 4
- Support polymorphic associations HOT 3
- Ignore modules
- Superclass mismatch
- Some mechanism for ignoring DSL code in classes HOT 1
- Be more optimistic with rake dependency (rake 11) HOT 3
- Can't generate mocks for rails Concerns HOT 14
- Error message "To see more/less detail set error_verbosity = 0, 1, 2, 3" very unclear. How do you set error_verbosity with rake? HOT 4
- Database type 'jsonb' is not a registered type. To register use ActiveRecordSchemaScrapper::Attributes.register_type(name: :jsonb, klass: <RubyClass>) HOT 5
- Support first_or_create on collection HOT 1
- undefined method `colorize' for "superclass must be a Class (Module given)":String HOT 5
- Constant values assigned to non sudo primitives objects
- Missing schema information on a non abstract model does not fail.
- Less warnings when generating for mixed model and non model files. HOT 1
- Using a default value for decimal data types results in a failing mock class generated in 2.2.3 and a mock class syntax error in version 2.0.0 HOT 5
- Calling update on a record should call save as well. 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 active_mocker.