iredelmeier / pseudo Goto Github PK
View Code? Open in Web Editor NEWA small mocking library for Rust
License: MIT License
A small mocking library for Rust
License: MIT License
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);
}
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`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.