
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
MockEM provides the same interface as EM (a.k.a. EventMachine), but simulates the passage of time to execute your scheduled actions without delay. It is intended for use in tests.
Uses Timecop for simulating the passage of time.
You'll need to add require 'mock_em'
, as well as require 'timecop'
.
At the beginning of your spec you can use the following snippet to mock EM within the scope of that spec.
# mock & restore EM
before(:all) do
@logger = Logger.new(STDOUT) # <-- Choose your own logger, as appropriate
# Mock EM
@orig_EM = EM
EM = MockEM::MockEM.new(@logger, Timecop)
end
after(:all) do
EM = @orig_EM
Timecop.return
end
Any references to EM
will then be using MockEM.
As a quick demonstration, the following code has a timer that would wait for 8 minutes with EM, but with MockEM it completes instantaneously:
require 'timecop'
require 'mock_em'
logger = Logger.new(STDOUT)
em = MockEM::MockEM.new(logger, Timecop)
em.run do
em.add_timer(8 * 60) do
puts "Done!"
em.stop
end
end
MockEM supports many of the features of EM. Example of supported methods:
run
, stop
, reactor_running?
next_tick
, add_timer
, add_periodic_timer
, cancel_timer
, get_max_timer_count
add_shutdown_hook
, error_handler
Refer to mock_em_spec.rb
for more details, as it runs the same set of specs against both MockEM
and EM
,
to verify the behavior is identical.
Your mileage may vary.
Ruby 1.8.7 and above is supported.
Pull requests welcome.
If you'd like to add missing functionality, you can use mock_em_spec.rb
to verify that the behavior is identical in both MockEM
and EM
.
Maintained by the RightScale "Cornsilk_team"
MIT License, see LICENSE
FAQs
Unknown package
We found that mock_em demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.