Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mock_em

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock_em

  • 0.2.1
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

MockEM

Gem Version Build Status Dependency Status Code Climate Coverage Status

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.

Getting Started

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    

Supported Features

MockEM supports many of the features of EM. Example of supported methods:

  • Reactor: run, stop, reactor_running?
  • Timers: next_tick, add_timer, add_periodic_timer, cancel_timer, get_max_timer_count
  • Hooks: 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.

Unsupported Features

Your mileage may vary.

Compatibility

Ruby 1.8.7 and above is supported.

Contributing

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.

Contributors

Maintained by the RightScale "Cornsilk_team"

License

MIT License, see LICENSE

FAQs

Package last updated on 20 Oct 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc