r/rust•
richhyd

Universal mocking library

Mocking is traditionally a hard problem in systems programming, since we don't have duck typing for faking things. However, I think I have found a solution, which I have published to crates.io. The method is actually very simple, if you want to see how it works, go to the github repo to vew the source.

Usage is as simple as

use universal_mocking_library::mock;
println!("{}", mock());

Posted Apr 1, 2019, 9:39 AM UTC

5512
PsichiX•

Sir, Your headphones cost less than $100.

14
yaymukund_•

you fight like a dairy farmer!

11
richhydOP•

I was trying to remember the ones from monkey island - love that game!

4
ssokolow•

"When my enemies saw me, they were petrified"

"Oh, is that your face? I thought it was your backside."

3
chris-morgan•
lazy_static::lazy_static! {
    static ref MOCKS: Vec<&'static str> = vec![
        …
    ];
}

Now you’re just asking to be mocked for using a lazy static and heap allocation. I’m thinking something based on “that’s just lazy!” but I don’t have heaps of time at present to pursue the perfect mockery out of it.

You should use this instead for greater efficiency:

static MOCKS: &'static [&'static str] = &[
    …
];
8
lfairy•

In recent versions of Rust, you don't need the 'static either!

static MOCKS: &[&str] = &[
    …
];

Such efficiency!

3
buldozr•

Does it automatically create mocks from UML diagrams?

7
richhydOP•

It'll mock you for using uml diagrams

45
ssokolow•

UML: Universal Mocking Language

15
sirak2010•

:)

3
hi_im_nate•

We thought we were mocking, but really we were being mocked the whole time.

5
[deleted]•

[deleted]

1
Fazer2•

You son of a silly person.

1