4 releases

0.2.2 Apr 16, 2024
0.1.2 Dec 8, 2023
0.1.1 Dec 8, 2023
0.1.0 Dec 8, 2023

#263 in Testing

Download history 33/week @ 2024-07-30 4/week @ 2024-09-24 2/week @ 2024-10-01 1/week @ 2024-10-08

191 downloads per month

MIT/Apache

67KB
1.5K SLoC

Rust Slim - Slim server for Rust

Develop Slim Fixtures for rust applications. Based on the Slim Protocol of fitnesse fitnesse .

This is not 100% compliant with the slim protocol right now. Here are some of the features that are known to not be implemented:

It can only handle string symbols and it cannot. It does not support a SUT for features. It does not support Actors. It does not support using the STOUD and STDIN for comunication.

This is currently in an unstable version. The general API can change in the next versions.

For more details, take a look at the documentation


lib.rs:

A (not yet complete) implementation of a SlimServer for acceptance testing.

This was implementating using the documentation found here

To add it to your project simply run:

cargo add rust_slim -F macros --dev

Then you need to create your fixtures. The recomended way of doing this is by using the #[fixture] macro. Here is an example:

use rust_slim::fixture;

#[derive(Default)]
pub struct Calculator {
    a: i64,
    b: i64,
}

#[fixture]
impl Calculator {
    pub fn set_a(&mut self, a: i64) {
        self.a = a
    }

    pub fn set_b(&mut self, b: i64) {
        self.b = b
    }

    pub fn sum(&self) -> i64 {
        self.a + self.b
    }

    pub fn mul(&self) -> i64 {
        self.a * self.b
    }

    pub fn sub(&self) -> i64 {
        self.a - self.b
    }

    pub fn div(&self) -> i64 {
        self.a / self.b
    }
}

All methods that are public will be able to be called by the slim server.

Than, we need to add an entrypoint to the slim server so we can run it. There are lot of ways of doing this. One is by creating an example in your project.

So create and example file called calculator.rs and add this:

use rust_slim::SlimServer;
use std::net::TcpListener;
use anyhow::Result;
use std::env::args;

#
#
#
#
#
#
#
fn main() -> Result<()> {
    let port = args().skip(1).next().unwrap_or("8085".to_string());
    let listener = TcpListener::bind(format!("0.0.0.0:{port}").to_string()).expect("Error");
    let (stream, _) = listener.accept()?;
    let mut server = SlimServer::new(stream.try_clone()?, stream);
    server.add_fixture::<Calculator>();
    server.run()?;
    Ok(())
}

Than, to run it, you simply call cargo run --example calculator. Now you need to configure your test runner (fitnesse, temoc) to call your server

Dependencies

~0.7–1.5MB
~27K SLoC