Crates.io | rb-sys-test-helpers |
lib.rs | rb-sys-test-helpers |
version | |
source | src |
created_at | 2023-04-14 13:25:42.013164+00 |
updated_at | 2025-01-11 19:52:11.458103+00 |
description | Helpers for testing Ruby extensions from Rust |
homepage | https://github.com/oxidize-rb/rb-sys |
repository | https://github.com/oxidize-rb/rb-sys |
max_upload_size | |
id | 839169 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
rb-sys-test-helpers
Helpers for testing Ruby extensions from Rust
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));
}
}
Licensed under either of
at your option.
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.