Module: Mockingbird

Defined in:
lib/mockingbird.rb,
lib/mockingbird/script.rb,
lib/mockingbird/server.rb,
lib/mockingbird/version.rb,
lib/mockingbird/commands.rb,
lib/mockingbird/script_runner.rb,
lib/mockingbird/connection_script.rb

Defined Under Namespace

Modules: Commands, Server Classes: ConnectionScript, Script, ScriptRunner

Constant Summary collapse

VERSION =
Version = "0.1.0"

Class Method Summary collapse

Class Method Details

.setup(opts = {}, &block) ⇒ Object

Convenience method for starting a mockingbird server during a test. This will be most users’ primary interface to mockingbird. The mockingbird server will be forked as a separate process. Ensure that your test code always calls teardown at some point after setup, or the separate process will not be terminated.

Options are

:host - The host to listen on. 0.0.0.0 by default
:port - The port to listen on. 4879 by default

The block is a Mockingbird configuration (see README).



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mockingbird.rb', line 28

def setup(opts={},&block)
  Server.configure(&block)
  @pid = fork do
    opts = {:host=>'0.0.0.0',:port=>4879}.merge(opts)
    $0 = "mockingbird:#{opts[:host]}:#{opts[:port]}"
    Server.start!(opts)
  end
  Process.detach(@pid)
  puts "Waiting for Mockingbird to start..."
  sleep(1) # Necessary to make sure the forked proc is up and running
  @pid
end

.teardownObject

Terminates the mockingbird server created by a call to setup. Make sure to always pair this call with setup to ensure that mockingbird server processes don’t linger. If you’re using test/unit, the recommended pattern is to actually call setup and teardown here during the setup and teardown phase of your unit tests. Otherwise, use the following pattern:

def test_something
  Mockingbird.setup(:port=>NNNN) do
    # config here
  end
  # do tests
ensure
  Mockingbird.teardown
end


55
56
57
# File 'lib/mockingbird.rb', line 55

def teardown
  Process.kill('KILL',@pid)
end