6 releases

0.2.0 Aug 3, 2023
0.1.4 May 24, 2023
0.1.1 Apr 25, 2023

#288 in Build Utils

Download history 61/week @ 2023-12-19 59/week @ 2023-12-26 163/week @ 2024-01-02 129/week @ 2024-01-09 124/week @ 2024-01-16 73/week @ 2024-01-23 53/week @ 2024-01-30 78/week @ 2024-02-06 145/week @ 2024-02-13 332/week @ 2024-02-20 630/week @ 2024-02-27 301/week @ 2024-03-05 492/week @ 2024-03-12 203/week @ 2024-03-19 131/week @ 2024-03-26 44/week @ 2024-04-02

904 downloads per month

MIT/Apache

125KB
2.5K SLoC

rb-sys-test-helpers

Helpers for testing Ruby extensions from Rust

Usage

Add this to your Cargo.toml:

[dev-dependencies]
rb-sys-env = { version = "0.1" }
rb-sys-test-helpers = { version = "0.2" }

Then, in your crate's build.rs:

pub fn main() -> Result<(), Box<dyn std::error::Error>> {
    let _ = rb_sys_env::activate()?;

    Ok(())
}

Then, you can use the with_ruby_vm function in your tests:

#[cfg(test)]
mod tests {
    use rb_sys_test_helpers::ruby_test;
    use rb_sys::{rb_num2fix, rb_int2big, FIXNUM_P};

    #[ruby_test]
    fn test_something() {
        // Your test code here will have a valid Ruby VM (hint: this works with
        // the `magnus` crate, too!)
        //
        // ...

        let int = unsafe { rb_num2fix(1) };
        let big = unsafe { rb_int2big(9999999) };

        assert!(FIXNUM_P(int));
        assert!(!FIXNUM_P(big));
    }
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.3–3MB
~53K SLoC