Attribute Macro ruby_test

Source
#[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:

  1. The Ruby VM is setup and initialized once and only once.
  2. All code runs on the same OS thread.
  3. 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 _) };
}