module RatatuiRuby::TestHelper::GlobalState

Helpers for testing code that reads global state.

Applications often read ARGV and ENV at startup. Testing these code paths requires stubbing those constants. Doing it manually is brittle —tests that forget to restore the original values leak state.

These helpers swap the constants, yield to the block, and restore the originals automatically.

Example

def test_parses_command_line_flags
  with_argv(["--verbose", "--log=debug.log"]) do
    app = MyApp.new
    assert app.verbose?
    assert_equal "debug.log", app.log_path
  end
end

def test_reads_api_key_from_environment
  with_env("API_KEY", "test-key-1234") do
    client = APIClient.new
    assert_equal "test-key-1234", client.api_key
  end
end