test_helper.rb 888 字节
Newer Older
1
require File.expand_path('../../../load_paths', __FILE__)
2

3 4
require 'action_cable'
require 'active_support/testing/autorun'
5 6 7 8


require 'puma'

9
require 'mocha/setup'
T
Thomas Walpole 已提交
10

11
require 'rack/mock'
12

P
Pratik Naik 已提交
13 14
# Require all the stubs and models
Dir[File.dirname(__FILE__) + '/stubs/*.rb'].each {|file| require file }
P
Pratik Naik 已提交
15

16 17 18 19 20 21 22 23 24 25 26
require 'faye/websocket'
class << Faye::WebSocket
  remove_method :ensure_reactor_running

  # We don't want Faye to start the EM reactor in tests because it makes testing much harder.
  # We want to be able to start and stop EM loop in tests to make things simpler.
  def ensure_reactor_running
    # no-op
  end
end

P
Pratik Naik 已提交
27
class ActionCable::TestCase < ActiveSupport::TestCase
28 29 30 31 32 33
  def run_in_eventmachine
    EM.run do
      yield

      EM.run_deferred_callbacks
      EM.stop
P
Pratik Naik 已提交
34 35
    end
  end
36

37 38
  def spawn_eventmachine
    Thread.new { EventMachine.run } unless EventMachine.reactor_running?
39
  end
P
Pratik Naik 已提交
40
end