Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Contribute to GitLab
  • Sign in / Register
F
fluid-rs
  • Project
    • Project
    • Details
    • Activity
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
    • Locked Files
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Registry
    • Registry
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Boiethios
  • fluid-rs
  • Wiki
  • assertions

assertions

Last edited by Boiethios Nov 24, 2018
Page history

Here is the complete list of the implemented assertions. Note that the assertions marked as consuming consume the left part of the assertion, so there cannot be a chain of multiple assertions.

Those assertions print a more complete error message in the test functions marked as #[fact] or #[attribute]. They can be used in a standard #[test] function as well, but in this case, the location and the stringified version of the left side are not displayed in the failure message.

Various feature

Negation

(2 + 2).should().not().be_equal_to(5);

Chaining

"42".parse::<i32>().should().not().be_an_error()
    .and_should().contain(42);

Explanation

the_answer().should().be_equal_to(42).because("42 is the answer to the question");

Equality

(1 + 1).should().be_equal_to(2);

With precision (for floats only):

(0.999 * 2.).should().be_equal_to(2.01).with_precision(0.1);

Iterators (consuming assertions)

Containing something

Some(2).should().contain(2);
vec![1, 2, 3].should().contain(1);

Checking if empty

let empty_vec = Vec::<i32>::new();
empty_vec.should().be_empty();

Results

Checking if it is an error

"?".parse::<i32>().should().be_an_error();

Generic

When there is no specific needed assertion:

foo().should().have_the_property(|&n| n % 2 == 0)
    .because("the number must be even");
Clone repository

Home

List of assertions

Fact

Theory


Changelog

More Pages

New Wiki Page

Tip: You can specify the full path for the new file. We will automatically create any missing directories.