Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
That's what you get for hardcoding the data :) at least use a provider or repository pattern...
Btw that's a problem I've found tdd eliminates completely -
Yes, you're right, I know that there is this gem for it: minitest-stub-const.
When I had to do this it was a constant used as a default value for an instance variable in the initialize method. So I created a reader for the instance variable then I stubbed the reader, not the constant. -
Root825994y@netikras This is to store which images (logo sets) have been added to the project, their sizes, and their paths. As new sets can only be added via releases, hardcoding them in a constant seems better than storing them elsewhere, as it avoids disk and network access at the cost of a few kb of memory.
As the constant grows I’m sure I’ll get annoyed and abstract it out somehow. That should make the specs will be easier to write. -
Root825994y@katbreitin Thanks 😊
I haven’t had much to rant about. Not sure if that’s a good thing or not. -
@Root repository doesn't mean you have to store data in another medium :)
class MyRepo {
public String getValue1() {return "aaa";}
}
class MyService {
private MyRepo repo;
constructor(MyRepo repo) {this.repo = repo;}
// take data from the repo rather than hardcode it in the interactor
// inject mocked repo as you need it -
Root825994y@netikras I will likely end up doing something similar. The accepted pattern in this codebase is constants, however, so I’m sure I’ll catch some flak for bucking it. 🤦🏻♀️
-
@Root still counts as constants ;) indirectly accessible, but constants.
Inline constants is a terrible idea imo. Ir makes the codebase rigid and untestable [and non-mockable]. And violates the sOlid. So if you get heated for this you've got plenty of arguments up your sleeve. -
Root825994y@netikras Ahh, we’re not using inline constants — I can’t imagine anyone has a good argument for using those. They’re all class constants.
But in this case it’s a lot of data in a single constant (a hash of hashes), rather than an individual constant per set, and that is what’s causing the mocking difficulty.
Related Rants
-
linuxxx28So I've got a Linux related job (or, starting at monday). When people ask me what my new position is called, I...
-
VomBa16So this happened around 3 years ago in college. Some software was missing on a random PC in college, so the p...
-
Gnu-Not-Unix18Friend: Hey, can you fix my laptop? The hard drive is almost full. Me: (Looking through his folders) Maybe it...
Mocking hardcoded data in frozen constants in Rails is such a fucking pain! Why must this be so difficult!?
asfdfakldsjfuck
rant
and i run into this
rspec
ffs
two hours of time alone
rails