Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mocking attributes or macros #13

Open
bitwizeshift opened this issue Mar 16, 2023 · 0 comments
Open

Add mocking attributes or macros #13

bitwizeshift opened this issue Mar 16, 2023 · 0 comments
Labels
✨ Feature New feature being added

Comments

@bitwizeshift
Copy link
Owner

bitwizeshift commented Mar 16, 2023

This is a larger task that will make use of #11 in order to generate/define mock functionality.

The exact syntax/specifics are yet to be determined, but the idea is to support something like:

trait Turtle {
    fn pen_down(&mut self);
    fn pen_up(&mut self);
}

#[neotest::mock]
struct MockTurtle;

impl Turtle for MockTurtle {
    // Set this as a mock function
    #[neotest::mock_fn]
    fn pen_down(&mut self);
    #[neotest::mock_fn]
    fn pen_up(&mut self);
}

// ...

fn test_draw_circle() {
    let mut turtle = MockTurtle::new();
    let painter = Painter::new(&mut turtle);

    subtest!{ |calls_pen_down| 
        let expectation = neotest::expect_call!( turtle.pen_down() => Times(1) );

        painter.draw_circle(0, 0, 10);
        
        assert!(expectation.satisfied());
    }    
}

(Syntax/names are subject to change, but this is the general idea).

@bitwizeshift bitwizeshift added the ✨ Feature New feature being added label Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature New feature being added
Projects
None yet
Development

No branches or pull requests

1 participant