#[ruby_test]
Expand description
A proc-macro which generates a #[test]
function has access to a valid Ruby VM.
Doing this properly it is not trivial, so this function abstracts away the details. Under the hood, it ensures:
- The Ruby VM is setup and initialized once and only once.
- All code runs on the same OS thread.
- Exceptions are properly handled and propagated as Rust
Result<T, RubyException>
values.
ยงExample
use rb_sys_test_helpers_macros::ruby_test;
#[ruby_test]
fn test_it_works() {
unsafe { rb_sys::rb_eval_string("1 + 1\0".as_ptr() as _) };
}
#[ruby_test(gc_stress)]
fn test_with_stress() {
unsafe { rb_sys::rb_eval_string("puts 'GC is stressing me out.'\0".as_ptr() as _) };
}