Code Monkey home page Code Monkey logo

pseudo's Issues

Feature Request: Sequential Returns

struct MyMock {
    pub mock_do_stuff: Mock<(), i32>,
}

impl MyMock {
    pub fn do_stuff(&self) -> i32 {
        self.mock_do_stuff.call(())
    }
}

impl Default for MyMock {
    fn default() -> MyMock {
        MyMock {
            mock_do_stuff: Mock::new(10),
        }
    }
}

#[test]
pub fn playground() {
    let mock = MyMock::default();

    assert_eq!(mock.do_stuff(), 10);

    mock.mock_do_stuff.return_value(42);
    mock.mock_do_stuff.return_value(84);

    let result1 = mock.do_stuff();
    let result2 = mock.do_stuff();

    assert_eq!(result1, 42); // returns 84; desire is it would return 42 on the first call and 84 on any remaining calls.
    assert_eq!(result2, 84);
}

Can't mock a Send Trait

Pseudo cannot mock a trait that is Send. Example:

    fn send() {
        pub trait A {
            fn foo(&self);
        }

        struct MockA {
            foo: Mock<(), ()>
        }
        impl A for MockA {
            fn foo(&self) {
                self.foo.call(())
            }
        }

        let mock = MockA{foo: Mock::default()};
        let _ = Box::new(mock) as Box<A + Send>;
    }

gives the following error:

error[E0277]: `(dyn std::ops::Fn(()) + 'static)` cannot be shared between threads safely
   --> src/t_pseudo.rs:431:17
    |
431 |         let _ = Box::new(mock) as Box<A + Send>;
    |                 ^^^^^^^^^^^^^^ `(dyn std::ops::Fn(()) + 'static)` cannot be shared between threads safely                                                   
    |
    = help: the trait `std::marker::Sync` is not implemented for `(dyn std::ops::Fn(()) + 'static)`
    = note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique<(dyn std::ops::Fn(()) + 'static)>`
    = note: required because it appears within the type `std::boxed::Box<(dyn std::ops::Fn(()) + 'static)>`
    = note: required because it appears within the type `std::option::Option<std::boxed::Box<(dyn std::ops::Fn(()) + 'static)>>`
    = note: required because of the requirements on the impl of `std::marker::Sync` for `std::sync::RwLock<std::option::Option<std::boxed::Box<(dyn std::ops::Fn(()) + 'static)>>>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<std::sync::RwLock<std::option::Option<std::boxed::Box<(dyn std::ops::Fn(()) + 'static)>>>>`
    = note: required because it appears within the type `pseudo::Mock<(), ()>`
    = note: required because it appears within the type `<t_pseudo::t::Pseudo as TestSuite>::send::MockA`
    = note: required for the cast to the object type `dyn <t_pseudo::t::Pseudo as TestSuite>::send::A + std::marker::Send`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.