Speed Up Your Rails Specs
blog.originate.com
Speed Up Your Rails Specs
1–10 of 13 posts
Re: Speed Up Your Rails Specs
#2Extra complexity cost is insane and probably not worth it. Basically you move all your crazy stubbing and mocking out of test code and into application code. Do not do this unless you really, really need this kind of dependency injection.
Re: Speed Up Your Rails Specs
#3Even better:
expect("my_service.rb", "line X").to be("widget_factory.create")
Or yet better, simply:
; # realize that testing the exact implementation is bullshit
Re: Speed Up Your Rails Specs
#4Re: Speed Up Your Rails Specs
#5Re: Speed Up Your Rails Specs
#6RE: Developing Decoupled Code Extra complexity cost is insane and probably not worth it. Basically you move all your crazy stubbing and mocking out of test code and into application code. Do not do this unless you really, really need this kind of dependency injection.
Now, we mock people who don't.
My, how different the web is!
Re: Speed Up Your Rails Specs
#7This is fine if all you want to do is unit test your classes. That's beside the point though -- I would posit if you're bolting dependency injection onto your interfaces just to make your tests faster, you're not doing it right. Instead, bring that dependency injection into the forefront: to the constructor. Yes, this means to make an object, you'll have to make another object first, both in your production and test code. But now your interface acts the same way in both places. If this sounds very Java-like, well... maybe Java got it right. (There was an article on the Twitter blog in the early days about this but I can't remember where it is now...)
Of course, this is going to introduce complexity and now you have to decide whether that complexity is worth it.
Re: Speed Up Your Rails Specs
#8Re: Speed Up Your Rails Specs
#9RE: Developing Decoupled Code Extra complexity cost is insane and probably not worth it. Basically you move all your crazy stubbing and mocking out of test code and into application code. Do not do this unless you really, really need this kind of dependency injection.
Back in the day, we laughed at people who stuffed all their code into button click handlers. Now, we mock people who don't . My, how different the web is!
Re: Speed Up Your Rails Specs
#10speed up by 10? Move to python. Speed up by 100? Move to Go. Speed up by 1000? Move to C++.