diff --git a/ext/wry_ruby/src/application/window.rs b/ext/wry_ruby/src/application/window.rs index 58ef77e..3e94135 100644 --- a/ext/wry_ruby/src/application/window.rs +++ b/ext/wry_ruby/src/application/window.rs @@ -40,13 +40,11 @@ pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool,timeout } => *control_flow = ControlFlow::Exit, _ => (), } - let elapsed = Instant::now() - start_time; if elapsed >= timeout_duration { - println!("Window creation timed out after {:?}.", timeout_duration); - // Handle the timeout error here - *control_flow = ControlFlow::Exit; + panic!("Window creation timed out after {:?}.", timeout_duration); } + }); } diff --git a/test/test_wry_ruby.rb b/test/test_wry_ruby.rb index 51262bb..27b562a 100644 --- a/test/test_wry_ruby.rb +++ b/test/test_wry_ruby.rb @@ -1,11 +1,19 @@ require "test_helper" +require "timeout" class TestWryRuby < Minitest::Test - # def test_that_it_has_a_version_number - # refute_nil ::WryRuby::VERSION - # end - def test_hello_wry - new_window "Hello Wry", 100, 400, true, 2 # title, width, height, resizable, timeout to close window for tests + timeout_seconds = 1 + assert_timeout(timeout_seconds) do + new_window "Hello Wry", 100, 400, true, 1 # title, width, height, resizable + end + end + + private + + def assert_timeout(timeout_seconds, &block) + Timeout.timeout(timeout_seconds, &block) + rescue Timeout::Error + raise "Window creation timed out after #{timeout_seconds}s." end end