[][src]Struct mockiato::Argument

pub struct Argument(_);

A factory for creating argument matchers

Methods

impl Argument[src]

pub fn any(&self) -> AnyArgumentMatcher[src]

Crates an argument matcher that matches any value.

Examples

use mockiato::{mockable, Argument};

#[cfg_attr(test, mockable)]
trait MessageSender {
    fn send_message(&self, message: &str);
}

let mut sender = MessageSenderMock::new();
let message = "Don't make lemonade";
sender.expect_send_message(Argument::any).returns(());
sender.send_message(message);

impl Argument[src]

pub fn nearly_eq<T, U>(&self, value: T) -> NearlyEqArgumentMatcher<T, U> where
    T: NearlyEq<T, U> + MaybeDebug,
    U: MaybeDebug, 
[src]

Creates an argument matcher that matches values using NearlyEq. Uses the default epsilon value defined by NearlyEq.

Examples

use mockiato::mockable;

#[cfg_attr(test, mockable)]
trait FloatFormatter {
    fn format_float(&self, value: f64) -> String;
}

let expected_result = String::from("0.3");
let mut formatter = FloatFormatterMock::new();
formatter
    .expect_format_float(|arg| arg.nearly_eq(0.3))
    .returns(expected_result.clone());

assert_eq!(expected_result, formatter.format_float(0.1 + 0.2),)

pub fn nearly_eq_with_accuracy<T, U>(
    &self,
    value: T,
    accuracy: U
) -> NearlyEqArgumentMatcher<T, U> where
    T: NearlyEq<T, U> + MaybeDebug,
    U: MaybeDebug, 
[src]

Creates an argument matcher that matches values using NearlyEq. A custom epislon value can be passed.

Examples

use mockiato::mockable;

#[cfg_attr(test, mockable)]
trait FloatFormatter {
    fn format_float(&self, value: f64) -> String;
}

let expected_result = String::from("0.3");
let mut formatter = FloatFormatterMock::new();
formatter
    .expect_format_float(|arg| arg.nearly_eq_with_accuracy(0.3, 1e-10))
    .returns(expected_result.clone());

assert_eq!(expected_result, formatter.format_float(0.1 + 0.2),)

impl Argument[src]

pub fn partial_eq<T>(&self, value: T) -> PartialEqArgumentMatcher<T>[src]

Creates an argument matcher that matches values using PartialEq.

Examples

use mockiato::mockable;

#[cfg_attr(test, mockable)]
trait MessageSender {
    fn send_message(&self, message: &str);
}

let mut sender = MessageSenderMock::new();
let message = "Hello World";
sender
    .expect_send_message(|arg| arg.partial_eq(message))
    .returns(());
sender.send_message(message);

pub fn partial_eq_owned<T>(&self, value: T) -> OwnedPartialEqArgumentMatcher<T>[src]

Creates an argument matcher that matches an owned value against references of itself using PartialEq.

Examples

use mockiato::mockable;

#[derive(Clone, PartialEq)]
enum Message {
    Ping,
}

#[cfg_attr(test, mockable)]
trait MessageSender {
    fn send_message(&self, message: &Message);
}

let mut sender = MessageSenderMock::new();
sender
    .expect_send_message(|arg| arg.partial_eq_owned(Message::Ping))
    .returns(());
sender.send_message(&Message::Ping);

impl Argument[src]

pub fn unordered_vec_eq<T>(&self, vec: Vec<T>) -> UnorderedVecArgumentMatcher<T>[src]

Creates an argument matcher that matches against Vecs and slices while disregarding the exact order of the elements.

Requires the elements to implement PartialEq.

Examples

use mockiato::mockable;

#[cfg_attr(test, mockable)]
trait MessageSender {
    fn send_message(&self, messages: &[&str]);
}

let mut sender = MessageSenderMock::new();
let message = "Hello World";
sender
    .expect_send_message(|arg| arg.unordered_vec_eq(vec!["foo", "bar", "baz"]))
    .returns(());
sender.send_message(&["baz", "bar", "foo"]);

Trait Implementations

impl Debug for Argument[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]