-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for exercises that depend on crates
- Loading branch information
Showing
6 changed files
with
155 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "mocks1" | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
mockall = "0.11.4" | ||
|
||
[[bin]] | ||
name = "mocks1" | ||
path = "mocks1.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// mocks1.rs | ||
// | ||
// Mockall is a powerful mock object library for Rust. It provides tools to create | ||
// mock versions of almost any trait or struct. They can be used in unit tests as | ||
// a stand-in for the real object. | ||
// | ||
// These tests each contain an expectation that defines some behaviour we expect on | ||
// calls to the function "foo". Add the "foo" function call and get the tests to pass | ||
// | ||
// I AM NOT DONE | ||
|
||
use mockall::*; | ||
use mockall::predicate::*; | ||
|
||
#[automock] | ||
trait MyTrait { | ||
fn foo(&self) -> bool; | ||
} | ||
|
||
fn follow_path_from_trait(x: &dyn MyTrait) -> String { | ||
if ??? { | ||
String::from("Followed path A") | ||
} | ||
else { | ||
String::from("Followed path B") | ||
} | ||
} | ||
|
||
#[test] | ||
fn can_follow_path_a() { | ||
let mut mock = MockMyTrait::new(); | ||
mock.expect_foo() | ||
.times(1) | ||
.returning(||true); | ||
assert_eq!(follow_path_from_trait(&mock), "Followed path A"); | ||
} | ||
|
||
#[test] | ||
fn can_follow_path_b() { | ||
let mut mock = MockMyTrait::new(); | ||
mock.expect_foo() | ||
.times(1) | ||
.returning(||false); | ||
assert_eq!(follow_path_from_trait(&mock), "Followed path B"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters