Skip to content
Janko Marohnić edited this page Sep 21, 2015 · 19 revisions

See the spec/integration directory which contains tests for the example applications. You should add em-synchrony to your Gemfile.

gem 'em-synchrony'

Use the goliath testing helpers:

require 'goliath/test_helper'
RSpec.configure do |c| 
  c.include Goliath::TestHelper, :example_group => {
    :file_path => /spec\/integration/
  }
end

Mocking a database adpater:

describe MyAPI do
  def mock_mysql api
    api.config['mysql'] = mock('mysql').as_null_object
  end

  it "my" do
    with_api(MyAPI) do |a|
      mock_mysql a
      EM.stop 
    end
  end
end

Testing a sub-route. A sub-route inherits its parent's middleware, so you can't test it in isolation if you need the parent middleware behavior. Instead you can test the parent route and use the :path option.

with_api(Parent) do
  post_request(:path => '/sub') do ...
end

The :domain option sends a request to a specific domain and port. The :domain parameter can be used in conjunction with the :path parameter.

with_api(Parent) do
  post_request(:domain => 'foobar.localhost:42', :path => '/sub') do ...
end

You can specify a path for storage of log output by passing the path to the desired logfile, relative to the application root, as follows:

with_api(Parent, {:log_file => 'path/to_log.log'}) do
  post_request(:path => '/sub') do ...
end